import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXMOrganizationManagementTeamEntityService, RootConfig } from './acorex-modules-organization-management.mjs';
import { entityMasterCrudActions, entityMasterDeleteAction } from '@acorex/platform/layout/entity';

async function factory(injector) {
    const dataService = injector.get(AXMOrganizationManagementTeamEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'team';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.team.name,
        icon: RootConfig.entities.team.icon,
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'extra-properties' },
        ],
        title: RootConfig.entities.team.title,
        formats: {
            individual: `@${i18n}:team.individual-title`,
            plural: `@${i18n}:team.plural-title`,
            searchResult: {
                title: '{{ title }}',
                description: RootConfig.module.title,
            },
        },
        relatedEntities: [],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                schema: {
                    dataType: 'uuid',
                    hidden: true,
                    nullable: false,
                    readonly: true,
                    unique: {
                        enabled: true,
                    },
                },
            },
            {
                name: 'title',
                title: `@general:terms.common.title`,
                groupId: 'basic-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'leaderId',
                title: `@general:terms.people.leader`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `HumanCapitalManagement.Employee`,
                            textField: 'party.displayName',
                            valueField: 'id',
                            expose: [
                                { source: 'id', target: 'leader.id' },
                                { source: 'party.displayName', target: 'leader.party.displayName' },
                            ],
                        },
                    },
                },
                options: {
                    sort: {
                        enabled: false,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
            },
            {
                name: 'memberIds',
                title: `@general:terms.people.member`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `HumanCapitalManagement.Employee`,
                            textField: 'party.displayName',
                            valueField: 'id',
                            multiple: true,
                            expose: [
                                { source: 'id', target: 'member.{contact}.id' },
                                { source: 'party.displayName', target: 'member.{contact}.displayName' },
                            ],
                        },
                    },
                },
                options: {
                    sort: {
                        enabled: false,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
            },
            {
                name: 'description',
                title: `@general:terms.common.description`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                    },
                },
            },
        ],
        columns: [
            { name: 'title' },
            { name: 'leaderId', options: { dataPath: 'leader.party.displayName' } },
            { name: 'description' },
        ],
        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',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                            },
                        },
                        {
                            id: 'organizationalStructure',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 6 },
                                    lg: { colSpan: 8 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'leaderId',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 6 },
                                    lg: { colSpan: 4 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'memberIds',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                            },
                        },
                        {
                            id: 'organizationalStructure',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 6 },
                                    lg: { colSpan: 8 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'leaderId',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 6 },
                                    lg: { colSpan: 4 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'memberIds',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                            },
                        },
                        {
                            id: 'organizationalStructure',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 6 },
                                    lg: { colSpan: 8 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'leaderId',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 6 },
                                    lg: { colSpan: 4 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'memberIds',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    sm: { colSpan: 12 },
                                    md: { colSpan: 12 },
                                    lg: { colSpan: 12 },
                                },
                                label: {
                                    visible: true,
                                },
                            },
                        },
                    ],
                    actions: [
                        entityMasterDeleteAction()
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions()
                    ],
                    views: [createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-organization-management-team.entity-p0nXmOOD.mjs.map
