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.learningPathCourse.name,
        title: RootConfig.entities.learningPathCourse.title,
        icon: RootConfig.entities.learningPathCourse.icon,
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }],
        formats: {
            individual: RootConfig.entities.learningPathCourse.title,
            plural: RootConfig.entities.learningPathCourse.titlePlural,
            searchResult: {
                title: '{{ course.title }}',
                description: '{{ orderIndex }}',
            },
        },
        groups: [
            {
                id: 'basic-info',
                title: '@learning-management:learning-paths.entities.learning-path-course.groups.basic-info',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'learningPathId',
                title: '@learning-management:learning-paths.entities.learning-path-course.fields.learning-path-id.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.learningPath.name}`,
                            look: 'select',
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'courseId',
                title: '@learning-management:learning-paths.entities.learning-path-course.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: 'orderIndex',
                title: '@learning-management:learning-paths.entities.learning-path-course.fields.order-index.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 1,
                            step: 1,
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
        ],
        columns: [{ name: 'orderIndex' }, { name: 'courseId', options: { dataPath: 'course.title' } }],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }],
                    properties: [
                        { name: 'learningPathId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'orderIndex', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }],
                    properties: [
                        { name: 'learningPathId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'orderIndex', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                    ],
                },
                single: {
                    title: '{{ course.title }}',
                    sections: [{ id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }],
                    properties: [
                        { name: 'learningPathId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'courseId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'orderIndex', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'orderIndex', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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