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.certificate.name,
        title: RootConfig.entities.certificate.title,
        icon: RootConfig.entities.certificate.icon,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'archive' }, { name: 'attachments' }],
        formats: {
            individual: RootConfig.entities.certificate.title,
            plural: RootConfig.entities.certificate.titlePlural,
            searchResult: {
                title: '{{ certificateType.name }}',
                description: '{{ employee.displayName }}',
            },
        },
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.certificateDefinition.name}`,
                title: RootConfig.entities.certificateDefinition.title,
                columns: ['title', 'certificateTypeId', 'courseId'],
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{ certificateDefinitionId }}',
                    },
                ],
                layout: { type: 'page-detail', position: 'before', order: 0 },
            },
        ],
        groups: [
            { id: 'basic-info', title: '@learning-management:certificates.entities.certificate.groups.basic-info' },
            { id: 'validity', title: '@learning-management:certificates.entities.certificate.groups.validity' },
            { id: 'documents', title: '@learning-management:certificates.entities.certificate.groups.documents' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'certificateDefinitionId',
                title: '@learning-management:certificates.entities.certificate.fields.certificate-definition-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.certificateDefinition.name}`,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'certificateDefinition.id' },
                                { source: 'title', target: 'certificateDefinition.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'certificateTypeId',
                title: '@learning-management:certificates.entities.certificate.fields.certificate-type-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.certificateType.name}`,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'certificateType.id' },
                                { source: 'name', target: 'certificateType.name' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'employeeId',
                title: '@learning-management:certificates.entities.certificate.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: 'courseId',
                title: '@learning-management:certificates.entities.certificate.fields.course-id.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.course.name}`,
                            expose: [
                                { source: 'id', target: 'course.id' },
                                { source: 'title', target: 'course.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'issueDate',
                title: '@learning-management:certificates.entities.certificate.fields.issue-date.title',
                groupId: 'validity',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsList.Editors.DateTimeBox,
                        options: {
                            displayFormat: 'date',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'expiryDate',
                title: '@learning-management:certificates.entities.certificate.fields.expiry-date.title',
                groupId: 'validity',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsList.Editors.DateTimeBox,
                        options: {
                            displayFormat: 'date',
                        },
                    },
                },
            },
            {
                name: 'fileId',
                title: '@learning-management:certificates.entities.certificate.fields.file-id.title',
                groupId: 'documents',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: 'DocumentManagement.DocumentFile',
                        },
                    },
                },
            },
            {
                name: 'notes',
                title: '@learning-management:certificates.entities.certificate.fields.notes.title',
                groupId: 'documents',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                            placeholder: '@learning-management:certificates.entities.certificate.fields.notes.placeholder',
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'certificateDefinitionId', options: { dataPath: 'certificateDefinition.title' } },
            { name: 'certificateTypeId', options: { dataPath: 'certificateType.name' } },
            { name: 'employeeId', options: { dataPath: 'employee.displayName' } },
            { name: 'courseId', options: { dataPath: 'course.title' } },
            { name: 'issueDate' },
            { name: 'expiryDate' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'validity', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'documents', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'certificateTypeId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'certificateDefinitionId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'issueDate', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'expiryDate', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'fileId', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 8 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'validity', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'documents', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'certificateTypeId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'certificateDefinitionId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'issueDate', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'expiryDate', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'fileId', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 8 } } } },
                    ],
                },
                single: {
                    title: '{{ certificateType.name }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'validity', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'documents', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'certificateTypeId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'certificateDefinitionId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'issueDate', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'expiryDate', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'fileId', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 8 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'issueDate', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-learning-management-certificate.entity-BavQuFHb.mjs.map
