"use strict";
var __webpack_exports__ = {};
const client_namespaceObject = require("@tachybase/client");
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
describe('CollectionFieldInterfaceManager', ()=>{
    let collectionFieldInterfaceManager;
    beforeEach(()=>{
        const app = new client_namespaceObject.Application();
        collectionFieldInterfaceManager = app.dataSourceManager.collectionFieldInterfaceManager;
    });
    describe('addFieldInterfaces', ()=>{
        it('should add field interfaces correctly', ()=>{
            class A extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'a');
                }
            }
            class B extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'b');
                }
            }
            collectionFieldInterfaceManager.addFieldInterfaces([
                A,
                B
            ]);
            const a = collectionFieldInterfaceManager.getFieldInterface('a');
            const b = collectionFieldInterfaceManager.getFieldInterface('b');
            expect(a).instanceOf(A);
            expect(b).instanceOf(B);
        });
        it('should override duplicates', ()=>{
            class A extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'a');
                }
            }
            class B extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'a');
                }
            }
            collectionFieldInterfaceManager.addFieldInterfaces([
                A,
                B
            ]);
            const a = collectionFieldInterfaceManager.getFieldInterface('a');
            expect(a).instanceOf(B);
        });
    });
    describe('getFieldInterface', ()=>{
        beforeEach(()=>{
            class A extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'a');
                }
            }
            collectionFieldInterfaceManager.addFieldInterfaces([
                A
            ]);
        });
        it('should return the correct interface by name', ()=>{
            const fieldInterface = collectionFieldInterfaceManager.getFieldInterface('a');
            expect(fieldInterface.name).toBe('a');
        });
        it('should return undefined for a non-existent interface', ()=>{
            const fieldInterface = collectionFieldInterfaceManager.getFieldInterface('nonExistentInterface');
            expect(fieldInterface).toBeUndefined();
        });
    });
    describe('getFieldInterfaces', ()=>{
        beforeEach(()=>{
            class A extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'a'), _define_property(this, "supportDataSourceType", [
                        'sourceA'
                    ]);
                }
            }
            class B extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'b'), _define_property(this, "notSupportDataSourceType", [
                        'sourceA'
                    ]);
                }
            }
            class C extends client_namespaceObject.CollectionFieldInterface {
                constructor(...args){
                    super(...args), _define_property(this, "name", 'c');
                }
            }
            collectionFieldInterfaceManager.addFieldInterfaces([
                A,
                B,
                C
            ]);
        });
        it('should return all stored interfaces when no dataSourceType is provided', ()=>{
            const interfaces = collectionFieldInterfaceManager.getFieldInterfaces();
            expect(interfaces.length).toBe(3);
        });
        it('should return supported interface when dataSourceType is provided', ()=>{
            const interfaces = collectionFieldInterfaceManager.getFieldInterfaces('sourceA');
            expect(interfaces.length).toBe(2);
            expect(interfaces[0].name).toBe('a');
            expect(interfaces[1].name).toBe('c');
        });
        it('should return empty array when an unsupported dataSourceType is provided', ()=>{
            const interfaces = collectionFieldInterfaceManager.getFieldInterfaces('sourceB');
            expect(interfaces.length).toBe(2);
            expect(interfaces[0].name).toBe('b');
            expect(interfaces[1].name).toBe('c');
        });
    });
    describe('addFieldInterfaceGroups', ()=>{
        it('should add field interface groups', ()=>{
            const groups = {
                group1: {
                    label: 'Group 1',
                    order: 1
                }
            };
            collectionFieldInterfaceManager.addFieldInterfaceGroups(groups);
            expect(collectionFieldInterfaceManager.getFieldInterfaceGroup('group1')).toEqual(groups.group1);
        });
    });
    describe('getFieldInterfaceGroups', ()=>{
        it('should return all field interface groups', ()=>{
            expect(collectionFieldInterfaceManager.getFieldInterfaceGroups()).toEqual({});
            const groups = {
                group1: {
                    label: 'Group 1',
                    order: 1
                }
            };
            collectionFieldInterfaceManager.addFieldInterfaceGroups(groups);
            expect(collectionFieldInterfaceManager.getFieldInterfaceGroups()).toEqual(groups);
        });
    });
    describe('getFieldInterfaceGroup', ()=>{
        it('should return the correct group by name', ()=>{
            const groups = {
                group1: {
                    label: 'Group 1',
                    order: 1
                }
            };
            collectionFieldInterfaceManager.addFieldInterfaceGroups(groups);
            expect(collectionFieldInterfaceManager.getFieldInterfaceGroup('group1')).toEqual(groups.group1);
        });
        it('should return undefined when the group does not exist', ()=>{
            expect(collectionFieldInterfaceManager.getFieldInterfaceGroup('nonExistentGroup')).toBeUndefined();
        });
    });
});
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
