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

//#region ----   Imports   ----
//#endregion
async function factory(injector) {
    const dataService = injector.get(AXMHumanCapitalManagementLeaveRequestEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'leave-request';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.leaveRequest.name,
        title: '@human-capital-management:leave-request.individual-title',
        icon: RootConfig.entities.leaveRequest.icon,
        plugins: [
            { name: 'history' },
            { name: 'attachments' },
            { name: 'archive' },
            { name: 'meta-data-form', options: { path: 'leaveTypeId' } }
        ],
        formats: {
            individual: '@human-capital-management:leave-request.individual-title',
            plural: '@human-capital-management:leave-request.plural-title',
            searchResult: { title: '{{ employee.party.displayName }}', description: RootConfig.module.title },
        },
        groups: [
            { id: 'basic-info', title: '@human-capital-management:leave-request.basic-info' },
            { id: 'period', title: '@general:terms.datetime.period' },
            { id: 'additional', title: '@general:terms.interface.additional-info' },
        ],
        properties: [
            { name: 'id', title: 'ID', groupId: 'basic-info', schema: { dataType: 'uuid', hidden: true, nullable: false, readonly: true, unique: { enabled: true } } },
            {
                name: 'employeeId',
                title: '@general:terms.people.employee',
                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.employee.name}`,
                            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: 'leaveTypeId',
                title: '@human-capital-management:leave-request.leaveTypeId',
                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.leaveType.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            columns: ['title'],
                            expose: [
                                { source: 'id', target: 'leaveType.id' },
                                { source: 'title', target: 'leaveType.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'startDate',
                title: '@general:terms.datetime.start-date',
                groupId: 'period',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                validations: [{ rule: 'required' }]
            },
            {
                name: 'endDate',
                title: '@general:terms.datetime.end-date',
                groupId: 'period',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                validations: [{ rule: 'required' }]
            },
            {
                name: 'durationDays',
                title: '@human-capital-management:leave-request.duration-days',
                groupId: 'period',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: { dataType: 'number', interface: { type: AXPWidgetsCatalog.number } }
            },
            {
                name: 'reason',
                title: '@human-capital-management:leave-request.reason',
                groupId: 'additional',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.largeText } }
            },
            {
                name: 'status',
                title: '@human-capital-management:leave-request.status',
                groupId: 'additional',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    readonly: true,
                    defaultValue: 'Pending',
                    nullable: false,
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'id',
                            readonly: true,
                            dataSource: [
                                { id: 'Pending', title: '@human-capital-management:leave-request.pending' },
                                { id: 'Approved', title: '@human-capital-management:leave-request.approved' },
                                { id: 'Rejected', title: '@human-capital-management:leave-request.rejected' },
                                { id: 'Cancelled', title: '@human-capital-management:leave-request.cancelled' },
                            ]
                        }
                    }
                }
            },
        ],
        columns: [
            { name: 'employeeId', options: { dataPath: 'employee.party.displayName' } },
            { name: 'leaveTypeId', options: { dataPath: 'leaveType.title' } },
            { name: 'startDate' },
            { name: 'endDate' },
            { name: 'durationDays' },
            { name: 'status' },
            { name: 'reason' },
        ],
        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: 'basic-info' }, { id: 'period' }, { id: 'additional' }],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'leaveTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'durationDays', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reason', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'period' }, { id: 'additional' }],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'leaveTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'durationDays', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reason', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{employee.party.displayName}}',
                    sections: [{ id: 'basic-info', order: 1 }, { id: 'period', order: 2 }, { id: 'additional', order: 3 }],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'leaveTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'durationDays', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reason', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({ sorts: [{ name: 'startDate', dir: 'desc' }] }),
                        createQueryView('pending', '@human-capital-management:leave-request.pending', true, {
                            conditions: [
                                {
                                    name: 'status',
                                    operator: { type: 'equal' },
                                    value: 'Pending',
                                },
                            ],
                        }),
                        createQueryView('approved', '@human-capital-management:leave-request.approved', true, {
                            conditions: [
                                {
                                    name: 'status',
                                    operator: { type: 'equal' },
                                    value: 'Approved',
                                },
                            ],
                        }),
                        createQueryView('rejected', '@human-capital-management:leave-request.rejected', true, {
                            conditions: [
                                {
                                    name: 'status',
                                    operator: { type: 'equal' },
                                    value: 'Rejected',
                                },
                            ],
                        }),
                        createQueryView('cancelled', '@human-capital-management:leave-request.cancelled', true, {
                            conditions: [
                                {
                                    name: 'status',
                                    operator: { type: 'equal' },
                                    value: 'Cancelled',
                                },
                            ],
                        }),
                    ]
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-human-capital-management-leave-request.entity-YGyl6MWh.mjs.map
