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.course.name,
        title: RootConfig.entities.course.title,
        icon: RootConfig.entities.course.icon,
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'clone' },
            { name: 'archive' },
            { name: 'attachments' },
            { name: 'tags' },
        ],
        formats: {
            individual: RootConfig.entities.course.title,
            plural: RootConfig.entities.course.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ code }}',
            },
        },
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.training.name}`,
                title: RootConfig.entities.training.titlePlural,
                columns: ['startDate', 'endDate', 'status', 'trainingTypeId'],
                conditions: [
                    {
                        name: 'courseId',
                        operator: { type: 'equal' },
                        value: '{{ id }}',
                    },
                ],
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.certificateDefinition.name}`,
                title: RootConfig.entities.certificateDefinition.titlePlural,
                columns: ['certificateTypeId', 'validityDays', 'isActive'],
                conditions: [
                    {
                        name: 'courseId',
                        operator: { type: 'equal' },
                        value: '{{ id }}',
                    },
                ],
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.certificate.name}`,
                title: RootConfig.entities.certificate.titlePlural,
                columns: ['certificateTypeId', 'issueDate', 'expiryDate'],
                conditions: [
                    {
                        name: 'courseId',
                        operator: { type: 'equal' },
                        value: '{{ id }}',
                    },
                ],
            },
        ],
        groups: [
            { id: 'basic-info', title: '@learning-management:courses.entities.course.groups.basic-info' },
            { id: 'settings', title: '@learning-management:courses.entities.course.groups.settings' },
            { id: 'relationships', title: '@learning-management:courses.entities.course.groups.relationships' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'code',
                title: '@learning-management:courses.entities.course.fields.code.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: '@learning-management:courses.entities.course.fields.code.placeholder',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'title',
                title: '@learning-management:courses.entities.course.fields.title.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: '@learning-management:courses.entities.course.fields.title.placeholder',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'description',
                title: '@learning-management:courses.entities.course.fields.description.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 6,
                            placeholder: '@learning-management:courses.entities.course.fields.description.placeholder',
                        },
                    },
                },
            },
            {
                name: 'courseTypeId',
                title: '@learning-management:courses.entities.course.fields.course-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.courseType.name}`,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'courseType.id' },
                                { source: 'name', target: 'courseType.name' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'durationHours',
                title: '@learning-management:courses.entities.course.fields.duration-hours.title',
                groupId: 'settings',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            step: 1,
                            placeholder: '@learning-management:courses.entities.course.fields.duration-hours.placeholder',
                        },
                    },
                },
            },
            {
                name: 'relatedSkillIds',
                title: '@learning-management:courses.entities.course.fields.related-skill-ids.title',
                groupId: 'relationships',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.skill.name}`,
                            multiple: true,
                            expose: [
                                { source: 'id', target: 'skills.{id}' },
                                { source: 'title', target: 'skills.{title}' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'certificateDefinitionIds',
                title: '@learning-management:courses.entities.course.fields.certificate-definition-ids.title',
                groupId: 'relationships',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.certificateDefinition.name}`,
                            multiple: true,
                            expose: [
                                { source: 'id', target: 'certificateDefinitions.{id}' },
                                { source: 'title', target: 'certificateDefinitions.{title}' },
                            ],
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'code' },
            { name: 'title' },
            { name: 'courseTypeId', options: { dataPath: 'courseType.name' } },
            { name: 'durationHours' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'relationships', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'code', layout: { positions: { lg: { colSpan: 4, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 8, order: 2 } } } },
                        { name: 'courseTypeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'durationHours', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'relatedSkillIds', layout: { positions: { lg: { colSpan: 12, order: 6 } } } },
                        { name: 'certificateDefinitionIds', layout: { positions: { lg: { colSpan: 12, order: 7 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'relationships', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'code', layout: { positions: { lg: { colSpan: 4, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 8, order: 2 } } } },
                        { name: 'courseTypeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'durationHours', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'relatedSkillIds', layout: { positions: { lg: { colSpan: 12, order: 6 } } } },
                        { name: 'certificateDefinitionIds', layout: { positions: { lg: { colSpan: 12, order: 7 } } } },
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'relationships', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'code', layout: { positions: { lg: { colSpan: 4, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 8, order: 2 } } } },
                        { name: 'courseTypeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'durationHours', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'relatedSkillIds', layout: { positions: { lg: { colSpan: 12, order: 6 } } } },
                        { name: 'certificateDefinitionIds', layout: { positions: { lg: { colSpan: 12, order: 7 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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