import { AXPWidgetsList, statusPlugin } from '@acorex/modules/common';
import { createAllQueryView } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { R as RootConfig } from './acorex-modules-assessment-management-acorex-modules-assessment-management-W8hHssaa.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function factory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.assessmentSession.name,
        title: RootConfig.entities.assessmentSession.title,
        icon: RootConfig.entities.assessmentSession.icon,
        plugins: [
            { name: 'history' },
            { name: 'audit-info' },
            {
                ...statusPlugin,
                options: {
                    definition: 'assessment-management.status.session',
                    field: 'statusId',
                },
            },
        ],
        formats: {
            individual: RootConfig.entities.assessmentSession.title,
            plural: RootConfig.entities.assessmentSession.titlePlural,
            searchResult: {
                title: '{{ responder.displayName }}',
                description: '{{ case.title }}',
            },
        },
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'time-tracking', title: '@assessment-management:sessions.entities.assessment-session.groups.time-tracking' },
            { id: 'progress', title: '@assessment-management:sessions.entities.assessment-session.groups.progress' },
            { id: 'answers', title: '@assessment-management:sessions.entities.assessment-session.groups.answers' },
            { id: 'override', title: '@assessment-management:sessions.entities.assessment-session.groups.override' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'caseId',
                title: '@assessment-management:sessions.entities.assessment-session.fields.case.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.assessmentCase.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            columns: ['title', 'status'],
                            expose: [
                                { source: 'id', target: 'case.id' },
                                { source: 'title', target: 'case.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'responderId',
                title: '@assessment-management:sessions.entities.assessment-session.fields.responder.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: 'SecurityManagement.User',
                            textField: 'displayName',
                            valueField: 'id',
                            look: 'select',
                            columns: ['displayName', 'username'],
                            expose: [
                                { source: 'id', target: 'responder.id' },
                                { source: 'displayName', target: 'responder.displayName' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'role',
                title: '@assessment-management:sessions.entities.assessment-session.fields.role.title',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    defaultValue: 'responder',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                {
                                    id: 'responder',
                                    title: '@assessment-management:sessions.entities.assessment-session.fields.role.options.responder',
                                },
                                {
                                    id: 'supervisor',
                                    title: '@assessment-management:sessions.entities.assessment-session.fields.role.options.supervisor',
                                },
                                {
                                    id: 'reviewer',
                                    title: '@assessment-management:sessions.entities.assessment-session.fields.role.options.reviewer',
                                },
                            ],
                        },
                    },
                },
            },
            {
                name: 'startedAt',
                title: '@assessment-management:sessions.entities.assessment-session.fields.started-at.title',
                groupId: 'time-tracking',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: { dataType: 'date', interface: { type: AXPWidgetsList.Editors.DateTimeBox, options: { readonly: true, format: 'datetime' } } },
            },
            {
                name: 'lastSavedAt',
                title: '@assessment-management:sessions.entities.assessment-session.fields.last-saved-at.title',
                groupId: 'time-tracking',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: { dataType: 'date', interface: { type: AXPWidgetsList.Editors.DateTimeBox, options: { readonly: true, format: 'datetime' } } },
            },
            {
                name: 'timeSpent',
                title: '@assessment-management:sessions.entities.assessment-session.fields.time-spent.title',
                groupId: 'time-tracking',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: { dataType: 'number', interface: { type: AXPWidgetsList.Editors.NumberBox, options: { readonly: true } } },
            },
            {
                name: 'progressPercentage',
                title: '@assessment-management:sessions.entities.assessment-session.fields.progress-percentage.title',
                groupId: 'progress',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: { dataType: 'number', interface: { type: AXPWidgetsList.Editors.NumberBox, options: { readonly: true, format: 'percent' } } },
            },
            {
                name: 'answeredQuestionsCount',
                title: '@assessment-management:sessions.entities.assessment-session.fields.answered-questions-count.title',
                groupId: 'progress',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: { dataType: 'number', interface: { type: AXPWidgetsList.Editors.NumberBox, options: { readonly: true } } },
            },
            {
                name: 'answers',
                title: '@assessment-management:sessions.entities.assessment-session.fields.answers.title',
                groupId: 'answers',
                options: { sort: { enabled: false }, filter: { advance: { enabled: false }, inline: { enabled: false } } },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsList.Advanced.AnswersViewer,
                        options: {},
                    },
                },
            },
            {
                name: 'previousId',
                title: '@assessment-management:sessions.entities.assessment-session.fields.previous.title',
                groupId: 'override',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.assessmentSession.name}`,
                            textField: 'responder.displayName',
                            valueField: 'id',
                            look: 'select',
                            columns: ['responder.displayName', 'role', 'createdAt'],
                            expose: [
                                { source: 'id', target: 'previous.id' },
                                { source: 'responderId', target: 'previous.responderId' },
                                { source: 'role', target: 'previous.role' },
                                { source: 'createdAt', target: 'previous.createdAt' },
                            ],
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'caseId', options: { dataPath: 'case.title' } },
            { name: 'responderId', options: { dataPath: 'responder.displayName' } },
            { name: 'role' },
            { name: 'statusId' },
            { name: 'answers' },
            { name: 'progressPercentage' },
            { name: 'startedAt' },
            { name: 'lastSavedAt' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'override', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'answers', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'caseId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'responderId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'role', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'previousId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'answers', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'time-tracking', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'progress', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'override', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'answers', order: 5, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'caseId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'responderId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'role', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startedAt', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'lastSavedAt', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'timeSpent', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'progressPercentage', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'answeredQuestionsCount', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'previousId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'answers', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{responder.displayName}}',
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'time-tracking', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'progress', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'override', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'answers', order: 5, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'caseId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'responderId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'role', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'startedAt', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'lastSavedAt', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'timeSpent', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'progressPercentage', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'answeredQuestionsCount', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'previousId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'answers', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({ sorts: [{ name: 'createdAt', dir: 'desc' }] }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { factory };
//# sourceMappingURL=acorex-modules-assessment-management-assessment-session.entity-Bohm1F0Z.mjs.map
