import { AXPWidgetsList } from '@acorex/modules/common';
import { createAllQueryView } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { RootConfig } from './acorex-modules-learning-management.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function factory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.enrollment.name,
        title: RootConfig.entities.enrollment.title,
        icon: RootConfig.entities.enrollment.icon,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'attachments' }],
        formats: {
            individual: RootConfig.entities.enrollment.title,
            plural: RootConfig.entities.enrollment.titlePlural,
            searchResult: {
                title: '{{ employee.displayName }}',
                description: '{{ training.title }} - {{ status }}',
            },
        },
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.attendance.name}`,
                title: RootConfig.entities.attendance.titlePlural,
                columns: ['sessionDate', 'status'],
                conditions: [
                    {
                        name: 'enrollmentId',
                        operator: { type: 'equal' },
                        value: '{{ id }}',
                    },
                ],
            },
        ],
        groups: [
            { id: 'basic-info', title: '@learning-management:enrollments.entities.enrollment.groups.basic-info' },
            { id: 'workflow', title: '@learning-management:enrollments.entities.enrollment.groups.workflow' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'employeeId',
                title: '@learning-management:enrollments.entities.enrollment.fields.employee-id.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: 'HumanCapitalManagement.Employee',
                            expose: [
                                { source: 'id', target: 'employee.id' },
                                { source: 'person.displayName', target: 'employee.displayName' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'trainingId',
                title: '@learning-management:enrollments.entities.enrollment.fields.training-id.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.training.name}`,
                            expose: [
                                { source: 'id', target: 'training.id' },
                                { source: 'course.title', target: 'training.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'status',
                title: '@learning-management:enrollments.entities.enrollment.fields.status.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    defaultValue: 'Requested',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                {
                                    id: 'Requested',
                                    title: '@learning-management:enrollments.entities.enrollment.fields.status.options.requested',
                                },
                                {
                                    id: 'Approved',
                                    title: '@learning-management:enrollments.entities.enrollment.fields.status.options.approved',
                                },
                                {
                                    id: 'Enrolled',
                                    title: '@learning-management:enrollments.entities.enrollment.fields.status.options.enrolled',
                                },
                                {
                                    id: 'Completed',
                                    title: '@learning-management:enrollments.entities.enrollment.fields.status.options.completed',
                                },
                                {
                                    id: 'Failed',
                                    title: '@learning-management:enrollments.entities.enrollment.fields.status.options.failed',
                                },
                                {
                                    id: 'Cancelled',
                                    title: '@learning-management:enrollments.entities.enrollment.fields.status.options.cancelled',
                                },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'workflowInstanceId',
                title: '@learning-management:enrollments.entities.enrollment.fields.workflow-instance-id.title',
                groupId: 'workflow',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: 'WorkflowManagement.WorkflowInstance',
                            look: 'popup',
                        },
                    },
                },
            },
            {
                name: 'notes',
                title: '@learning-management:enrollments.entities.enrollment.fields.notes.title',
                groupId: 'workflow',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                            placeholder: '@learning-management:enrollments.entities.enrollment.fields.notes.placeholder',
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'employeeId', options: { dataPath: 'employee.displayName' } },
            { name: 'trainingId', options: { dataPath: 'training.title' } },
            { name: 'status' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'workflow', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'trainingId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'workflowInstanceId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 5 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'workflow', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'trainingId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'workflowInstanceId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 5 } } } },
                    ],
                },
                single: {
                    title: '{{ employee.displayName }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'workflow', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'trainingId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'workflowInstanceId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 5 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'createdAt', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-learning-management-enrollment.entity-i-3o7Lp3.mjs.map
