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.mandatoryTrainingRule.name,
        title: RootConfig.entities.mandatoryTrainingRule.title,
        icon: RootConfig.entities.mandatoryTrainingRule.icon,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'disable' }],
        formats: {
            individual: RootConfig.entities.mandatoryTrainingRule.title,
            plural: RootConfig.entities.mandatoryTrainingRule.titlePlural,
            searchResult: {
                title: '{{ position.title }}',
                description: '{{ course.title }}',
            },
        },
        groups: [
            { id: 'basic-info', title: '@learning-management:compliance.entities.mandatory-training-rule.groups.basic-info' },
            { id: 'settings', title: '@learning-management:compliance.entities.mandatory-training-rule.groups.settings' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'positionId',
                title: '@learning-management:compliance.entities.mandatory-training-rule.fields.position-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: 'OrganizationManagement.Position',
                            expose: [
                                { source: 'id', target: 'position.id' },
                                { source: 'title', target: 'position.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'courseId',
                title: '@learning-management:compliance.entities.mandatory-training-rule.fields.course-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.course.name}`,
                            expose: [
                                { source: 'id', target: 'course.id' },
                                { source: 'title', target: 'course.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'frequencyMonths',
                title: '@learning-management:compliance.entities.mandatory-training-rule.fields.frequency-months.title',
                groupId: 'settings',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            step: 1,
                            placeholder: '@learning-management:compliance.entities.mandatory-training-rule.fields.frequency-months.placeholder',
                        },
                    },
                },
            },
            {
                name: 'notes',
                title: '@learning-management:compliance.entities.mandatory-training-rule.fields.notes.title',
                groupId: 'settings',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                            placeholder: '@learning-management:compliance.entities.mandatory-training-rule.fields.notes.placeholder',
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'positionId', options: { dataPath: 'position.title' } },
            { name: 'courseId', options: { dataPath: 'course.title' } },
            { name: 'frequencyMonths' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'positionId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'frequencyMonths', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'positionId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'frequencyMonths', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                    ],
                },
                single: {
                    title: '{{ position.title }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'settings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'positionId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'frequencyMonths', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'positionId', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-learning-management-mandatory-training-rule.entity-CtFeVKkC.mjs.map
