import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { b as AXMPartyRoleService, R as RootConfig } from './acorex-modules-party-management-acorex-modules-party-management-BkRsPvsw.mjs';

//#region ----   Imports   ----
//#endregion
async function partyRoleFactory(injector) {
    const dataService = injector.get(AXMPartyRoleService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.partyRole.name,
        title: RootConfig.entities.partyRole.title,
        icon: RootConfig.entities.partyRole.icon,
        formats: {
            individual: RootConfig.entities.partyRole.title,
            plural: RootConfig.entities.partyRole.titlePlural,
            searchResult: {
                title: RootConfig.entities.partyRole.title,
                description: '@party-management:party-role.search-result-description',
            },
        },
        plugins: [
            { name: 'archive' },
            { name: 'note' },
        ],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
        ],
        properties: [
            {
                name: 'partyId',
                title: '@party-management:party-role.properties.party.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.party.name}`,
                            multiple: false,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'roleId',
                title: '@party-management:party-role.properties.role.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            dataSource: 'party-role-types',
                            expose: [
                                { source: 'title', target: 'role.title' },
                                { source: 'id', target: 'role.id' },
                            ]
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'status',
                title: '@general:terms.status.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'id',
                            textField: 'title',
                            dataSource: [
                                { title: 'Active', id: 'Active' },
                                { title: 'Inactive', id: 'Inactive' },
                                { title: 'Suspended', id: 'Suspended' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'since',
                title: '@party-management:party-role.properties.since.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                },
            },
            {
                name: 'until',
                title: '@party-management:party-role.properties.until.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: false }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                },
            },
        ],
        columns: [
            { name: 'roleId', options: { dataPath: 'role.title' } },
            { name: 'status' },
            { name: 'since' },
            { name: 'until' },
        ],
        commands: {
            create: {
                execute: async (data) => {
                    const res = await dataService.insertOne(data);
                    return { id: res };
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        {
                            name: 'roleId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'status',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'since',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'until',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        {
                            name: 'roleId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'status',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'since',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'until',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{role}} - {{party.displayName}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'roleId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'status',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'since',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'until',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'since', dir: 'desc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { partyRoleFactory };
//# sourceMappingURL=acorex-modules-party-management-party-role.entity-BjV7pJZU.mjs.map
