import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { e as AXMHumanCapitalManagementPositionAssignmentEntityService, R as RootConfig } from './acorex-modules-human-capital-management-acorex-modules-human-capital-management-cb1hY8I2.mjs';

async function factory(injector) {
    const dataService = injector.get(AXMHumanCapitalManagementPositionAssignmentEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'position-assignment';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.positionAssignment.name,
        icon: 'fa-light fa-user-tie-hair',
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'extra-properties' }],
        title: '@human-capital-management:position-assignment.individual-title',
        formats: {
            individual: '@human-capital-management:position-assignment.individual-title',
            plural: '@human-capital-management:position-assignment.plural-title',
            searchResult: { title: '{{ position.title }}', description: RootConfig.module.title },
        },
        relatedEntities: [],
        groups: [
            { id: 'assignment', title: '@human-capital-management:position-assignment.assignment' },
            { id: 'period', title: '@general:terms.datetime.period' },
            { id: 'additional', title: '@general:terms.interface.additional-info' },
        ],
        properties: [
            { name: 'id', title: 'ID', groupId: 'assignment', schema: { dataType: 'uuid', hidden: true, nullable: false, readonly: true, unique: { enabled: true } } },
            {
                name: 'employeeId',
                title: '@general:terms.people.employee',
                groupId: 'assignment',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `HumanCapitalManagement.Employee`,
                            textField: 'party.displayName',
                            valueField: 'id',
                            look: 'select',
                            columns: ['party.displayName', 'employeeCode'],
                            expose: [
                                { source: 'id', target: 'employee.id' },
                                { source: 'party.displayName', target: 'employee.party.displayName' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'businessUnitId',
                title: '@organization-management:business-unit.individual-title',
                groupId: 'assignment',
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `OrganizationManagement.BusinessUnit`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'businessUnit.id' },
                                { source: 'title', target: 'businessUnit.title' },
                                { source: 'positionIds', target: 'businessUnit.positionIds' },
                                { source: 'positions', target: 'businessUnit.positions' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'positionId',
                title: '@general:terms.position',
                groupId: 'assignment',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `OrganizationManagement.Position`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            columns: ['title'],
                            expose: [
                                { source: 'id', target: 'position.id' },
                                { source: 'title', target: 'position.title' },
                            ],
                            filter: {
                                logic: 'and',
                                filters: [
                                    { field: 'id', operator: { type: 'in' }, value: '{{ context.eval("businessUnit.positionIds") }}' },
                                ],
                            },
                        },
                        triggers: [
                            { event: "{{ events.context('businessUnitId') }}", action: `{{ widget.refresh() }}` },
                        ],
                    },
                },
                validations: [{ rule: 'required' }],
            },
            { name: 'startDate', title: '@general:terms.datetime.start-date', groupId: 'period', schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } }, validations: [{ rule: 'required' }] },
            { name: 'endDate', title: '@general:terms.datetime.end-date', groupId: 'period', schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } } },
            { name: 'isPrimary', title: '@general:terms.status.states.is-primary', groupId: 'additional', schema: { dataType: 'boolean', interface: { type: AXPWidgetsCatalog.toggle } } },
            { name: 'notes', title: '@general:terms.common.notes', groupId: 'additional', schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.largeText } } },
        ],
        columns: [
            { name: 'employeeId', options: { dataPath: 'employee.party.displayName' } },
            { name: 'businessUnitId', options: { dataPath: 'businessUnit.title' } },
            { name: 'positionId', options: { dataPath: 'position.title' } },
            { name: 'startDate' },
            { name: 'endDate' },
            { name: 'isPrimary' },
        ],
        commands: {
            create: { execute: async (data) => ({ id: await dataService.insertOne(data) }) },
            delete: { execute: async (id) => await dataService.deleteOne(id) },
            update: { execute: async (data) => await dataService.updateOne(data.id, data) },
        },
        queries: {
            byKey: { execute: async (id) => await dataService.getOne(id), type: AXPEntityQueryType.Single },
            list: { execute: async (e) => await dataService.query(e), type: AXPEntityQueryType.List },
        },
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'assignment' }, { id: 'period' }, { id: 'additional' }], properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'positionId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'businessUnitId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isPrimary', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12 } } } },
                    ]
                },
                update: {
                    sections: [{ id: 'assignment' }, { id: 'period' }, { id: 'additional' }], properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'positionId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'businessUnitId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isPrimary', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12 } } } },
                    ]
                },
                single: {
                    title: `{{position.title}}`, sections: [{ id: 'assignment' }, { id: 'period' }, { id: 'additional' }], properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'positionId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'businessUnitId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isPrimary', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [...entityMasterRecordActions()]
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'startDate', dir: 'desc' }] })]
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-human-capital-management-position-assignment.entity-DBz-A04O.mjs.map
