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

async function factory(injector) {
    const dataService = injector.get(AXMHumanCapitalManagementEmployeeEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'employee';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.employee.name,
        title: '@human-capital-management:employee.individual-title',
        icon: 'fa-light fa-building',
        formats: {
            individual: '@human-capital-management:employee.individual-title',
            plural: '@human-capital-management:employee.plural-title',
            displayName: 'Employment Information',
            searchResult: { title: '{{ party.displayName }}', description: RootConfig.module.title },
        },
        plugins: [
            { name: 'identifier', options: { field: 'employeeCode', rule: 'employee-code' } },
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'extra-properties' },
            {
                name: 'attachments',
                options: { field: 'imageId', accept: '.jpg,.jpeg,.png,.pdf', multiple: true, fileEditable: true },
            },
            { name: 'archive' },
            {
                name: 'computed-property',
                options: {
                    fields: [
                        {
                            name: 'manager',
                            title: '@human-capital-management:employee.manager',
                            value: "{{ context.eval('manager.party.displayName') }}",
                            group: { id: 'organizationalStructure' },
                            showAs: { type: AXPWidgetsCatalog.text },
                        },
                        {
                            name: 'activePosition',
                            title: '@human-capital-management:employee.active-position',
                            value: 'Engineering Manager (placeholder)',
                            group: { id: 'organizationalStructure' },
                            showAs: { type: AXPWidgetsCatalog.text },
                        },
                    ],
                },
            },
        ],
        relatedEntities: [
            {
                entity: `PartyManagement.Party`,
                title: 'Personal Information',
                conditions: [{ name: 'id', operator: { type: 'equal' }, value: '{{ context.eval("partyId") }}' }],
                layout: { type: 'merge-detail' },
                persistence: {
                    dataPath: 'party',
                    strategy: 'referenced',
                    idField: 'partyId',
                },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.leaveRequest.name}`,
                title: '@human-capital-management:leave-request.plural-title',
                columns: ['leaveTypeId', 'startDate', 'endDate', 'durationDays', 'status', 'reason'],
                conditions: [entityDetailsSimpleCondition('employeeId')],
                actions: [...entityDetailsCrudActions('employeeId')],
                layout: { type: 'page-list', position: 'after', order: 4 },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.employeeSkill.name}`,
                title: 'Skills',
                columns: ['skillId', 'level', 'yearsOfExperience', 'lastUsedDate'],
                conditions: [entityDetailsSimpleCondition('employeeId')],
                actions: [...entityDetailsCrudActions('employeeId')],
                layout: { type: 'page-list', position: 'after', order: 2 },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.positionAssignment.name}`,
                title: '@human-capital-management:position-assignment.plural-title',
                columns: ['positionId', 'businessUnitId', 'startDate', 'endDate', 'isPrimary'],
                conditions: [entityDetailsSimpleCondition('employeeId')],
                actions: [...entityDetailsCrudActions('employeeId')],
                layout: { type: 'page-list', position: 'after', order: 3 },
            },
            {
                entity: `SecurityManagement.User`,
                title: 'Security Information',
                icon: 'fa-light fa-lock',
                conditions: [{ name: 'id', operator: { type: 'equal' }, value: '{{ context.eval("userId") }}' }],
                layout: { type: 'page-detail', position: 'after', order: 1 },
                persistence: {
                    dataPath: 'user',
                    strategy: 'referenced',
                    idField: 'userId',
                    hydrate: 'eager',
                    map: {
                        displayName: '$parent.party.displayName',
                    },
                },
            },
        ],
        groups: [
            { id: 'organizationalStructure', title: '@human-capital-management:employee.organizational-structure' },
            { id: 'employmentProfile', title: '@human-capital-management:employee.employment-profile' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'personalInformation',
                schema: { dataType: 'uuid', hidden: true, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'employeeCode',
                title: '@human-capital-management:employee.employee-code',
                groupId: 'employmentProfile',
                schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.text } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'roleId',
                title: '@human-capital-management:employee.roleId',
                groupId: 'organizationalStructure',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `OrganizationManagement.Role`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'role.id' },
                                { source: 'title', target: 'role.title' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'employmentTypeId',
                title: '@human-capital-management:employee.employmentTypeId',
                groupId: 'employmentProfile',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.employmentType.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'employmentType.id' },
                                { source: 'title', target: 'employmentType.title' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'hireDate',
                title: '@human-capital-management:employee.hire-date',
                groupId: 'employmentProfile',
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
        ],
        columns: [
            {
                name: 'party.displayName',
                title: '@general:terms.common.display-name',
                showAs: { type: AXPWidgetsCatalog.text },
            },
            {
                name: 'party.primaryContact',
                title: '@general:terms.communication.email',
                options: { width: '350px' },
                showAs: { type: AXPWidgetsCatalog.contact, options: { type: 'email' } },
            },
            // { name: 'party.mobile', title: '@general:terms.communication.mobile', options: { width: '250px' }, showAs: { type: AXPWidgetsCatalog.contact, options: { type: 'phone' } } },
            { name: 'user.username', title: '@general:terms.contact.username', showAs: { type: AXPWidgetsCatalog.text } },
            { name: 'employeeCode' },
            { name: 'roleId', options: { dataPath: 'role.title' } },
            { name: 'employmentTypeId', options: { dataPath: 'employmentType.title' } },
            { name: 'hireDate' },
        ],
        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) => {
                    const item = await dataService.getOne(id);
                    return item;
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    console.log('Employee List Query', e);
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'personalInformation' }, { id: 'organizationalStructure' }, { id: 'employmentProfile' }],
                    properties: [
                        { name: 'employeeCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'roleId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employmentTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'hireDate', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'personalInformation' }, { id: 'organizationalStructure' }, { id: 'employmentProfile' }],
                    properties: [
                        { name: 'employeeCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'roleId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employmentTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'hireDate', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{party.displayName}}',
                    sections: [
                        { id: 'personalInformation', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'employmentProfile', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'organizationalStructure', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'employeeCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'roleId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employmentTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'hireDate', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'party.displayName', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-human-capital-management-employee.entity-CP0J0udU.mjs.map
