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

async function factory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.position.name,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'clone' }, { name: 'category' }],
        title: RootConfig.entities.position.title,
        icon: RootConfig.entities.position.icon,
        formats: {
            individual: '@organization-management:positions.entities.position.title',
            plural: '@organization-management:positions.entities.position.plural',
            searchResult: {
                title: '{{ title }}',
                description: RootConfig.module.title,
            },
        },
        relatedEntities: [],
        groups: [
            {
                id: 'basic-info',
                title: `@general:terms.interface.basic-info`,
            },
            {
                id: 'organizational-details',
                title: '@organization-management:positions.entities.position.groups.organizational-details',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: {
                        enabled: true,
                    },
                },
            },
            {
                name: 'title',
                title: `@general:terms.common.title`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'code',
                title: `@general:terms.common.code`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'description',
                title: `@general:terms.common.description`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                    },
                },
            },
            {
                name: 'jobDefinitionId',
                title: '@organization-management:positions.entities.position.fields.job-definition.title',
                groupId: 'organizational-details',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.jobDefinition.name}`,
                            textField: 'title',
                            valueField: 'id',
                            expose: [
                                { source: 'id', target: 'jobDefinition.id' },
                                { source: 'title', target: 'jobDefinition.title' },
                                { source: 'jobLevelIds', target: 'jobDefinition.jobLevelIds' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'jobLevelId',
                title: '@organization-management:positions.entities.position.fields.job-level.title',
                groupId: 'organizational-details',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.jobLevel.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            disabled: '{{ !context.eval("jobDefinitionId") }}',
                            expose: [
                                { source: 'id', target: 'jobLevel.id' },
                                { source: 'title', target: 'jobLevel.title' },
                            ],
                            filter: {
                                logic: 'and',
                                filters: [
                                    {
                                        field: 'id',
                                        operator: { type: 'in' },
                                        value: '{{ context.eval("jobDefinition.jobLevelIds") }}',
                                    },
                                ],
                            },
                        },
                        triggers: [
                            {
                                event: "{{ events.context('jobDefinitionId') }}",
                                action: `{{ widget.refresh() }}`,
                            },
                        ],
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'businessUnitId',
                title: '@organization-management:positions.entities.position.fields.business-unit.title',
                groupId: 'organizational-details',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.businessUnit.name}`,
                            textField: 'title',
                            valueField: 'id',
                            //look: 'select',
                            expose: [
                                { source: 'id', target: 'businessUnit.id' },
                                { source: 'title', target: 'businessUnit.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'capacity',
                title: '@organization-management:positions.entities.position.fields.capacity.title',
                groupId: 'organizational-details',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                        },
                    },
                },
            },
        ],
        columns: [{ name: 'title' }, { name: 'description' }, { name: 'isManager' }],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'organizational-details',
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'jobDefinitionId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'jobLevelId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'businessUnitId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'capacity',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'organizational-details',
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'jobDefinitionId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'jobLevelId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'businessUnitId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'capacity',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            id: 'organizational-details',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 2,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'jobDefinitionId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'jobLevelId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'businessUnitId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'capacity',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [entityMasterDeleteAction()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

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