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.trainingDefinition.name,
        title: RootConfig.entities.trainingDefinition.title,
        icon: RootConfig.entities.trainingDefinition.icon,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'clone' }, { name: 'archive' }, { name: 'category' }],
        formats: {
            individual: RootConfig.entities.trainingDefinition.title,
            plural: RootConfig.entities.trainingDefinition.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ course.title }}',
            },
        },
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'defaults', title: '@learning-management:trainings.entities.training-definition.groups.defaults' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'title',
                title: '@learning-management:trainings.entities.training-definition.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:trainings.entities.training-definition.fields.title.placeholder',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'description',
                title: '@learning-management:trainings.entities.training-definition.fields.description.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 4,
                            placeholder: '@learning-management:trainings.entities.training-definition.fields.description.placeholder',
                        },
                    },
                },
            },
            {
                name: 'courseId',
                title: '@learning-management:trainings.entities.training-definition.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}`,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'course.id' },
                                { source: 'title', target: 'course.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'trainingTypeId',
                title: '@learning-management:trainings.entities.training-definition.fields.training-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.trainingType.name}`,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'trainingType.id' },
                                { source: 'name', target: 'trainingType.name' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'defaultDurationHours',
                title: '@learning-management:trainings.entities.training-definition.fields.default-duration-hours.title',
                groupId: 'defaults',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            placeholder: '@learning-management:trainings.entities.training-definition.fields.default-duration-hours.placeholder',
                        },
                    },
                },
            },
            {
                name: 'defaultCapacity',
                title: '@learning-management:trainings.entities.training-definition.fields.default-capacity.title',
                groupId: 'defaults',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            placeholder: '@learning-management:trainings.entities.training-definition.fields.default-capacity.placeholder',
                        },
                    },
                },
            },
            {
                name: 'defaultLocationId',
                title: '@learning-management:trainings.entities.training-definition.fields.default-location-id.title',
                groupId: 'defaults',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: 'LocationManagement.Location',
                            expose: [
                                { source: 'id', target: 'defaultLocation.id' },
                                { source: 'title', target: 'defaultLocation.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'isActive',
                title: '@learning-management:trainings.entities.training-definition.fields.is-active.title',
                groupId: 'defaults',
                schema: {
                    dataType: 'boolean',
                    defaultValue: true,
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                    },
                },
            },
        ],
        columns: [
            { name: 'title' },
            { name: 'courseId', options: { dataPath: 'course.title' } },
            { name: 'trainingTypeId', options: { dataPath: 'trainingType.name' } },
            { name: 'isActive' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'defaults', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'trainingTypeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'defaultDurationHours', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'defaultCapacity', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'defaultLocationId', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'isActive', layout: { positions: { lg: { colSpan: 3, order: 8 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'defaults', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'trainingTypeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'defaultDurationHours', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'defaultCapacity', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'defaultLocationId', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'isActive', layout: { positions: { lg: { colSpan: 3, order: 8 } } } },
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'defaults', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'trainingTypeId', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'defaultDurationHours', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'defaultCapacity', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'defaultLocationId', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'isActive', layout: { positions: { lg: { colSpan: 3, order: 8 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-learning-management-training-definition.entity-NQqJ5avw.mjs.map
