import { AXPWidgetsList, statusPlugin } from '@acorex/modules/common';
import { createAllQueryView, AXPEntityCommandScope } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions, entityDetailsCrudActions } 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.assessmentCase.name,
        title: RootConfig.entities.assessmentCase.title,
        icon: RootConfig.entities.assessmentCase.icon,
        plugins: [
            { name: 'history' },
            { name: 'audit-info' },
            {
                ...statusPlugin,
                options: {
                    definition: 'assessment-management.status.case',
                    field: 'statusId',
                },
            },
        ],
        formats: {
            individual: RootConfig.entities.assessmentCase.title,
            plural: RootConfig.entities.assessmentCase.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ questionnaire.title }}',
            },
        },
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.assessmentSession.name}`,
                title: RootConfig.entities.assessmentSession.titlePlural,
                columns: ['responderId', 'role', 'statusId', 'progressPercentage', 'startedAt', 'previousId'],
                conditions: [{ name: 'caseId', operator: { type: 'equal' }, value: '{{context.eval("id")}}' }],
                actions: [
                    ...entityDetailsCrudActions('caseId', {
                        create: false,
                        edit: false,
                        view: false
                    }),
                ],
            },
        ],
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'subject', title: '@assessment-management:cases.entities.assessment-case.groups.subject' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'questionnaireId',
                title: '@assessment-management:cases.entities.assessment-case.fields.questionnaire.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.questionnaire.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            columns: ['title', 'type'],
                            expose: [
                                { source: 'id', target: 'questionnaire.id' },
                                { source: 'title', target: 'questionnaire.title' },
                                { source: 'type', target: 'questionnaire.type' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'title',
                title: '@assessment-management:cases.entities.assessment-case.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 } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'description',
                title: '@assessment-management:cases.entities.assessment-case.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: 3 } } },
            },
            // SubjectRef
            {
                name: 'subjectRef.type',
                title: '@assessment-management:cases.entities.assessment-case.fields.subject-entity-name.title',
                groupId: 'subject',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: { dataType: 'string', interface: { type: AXPWidgetsList.Editors.TextBox } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'subjectRef.id',
                title: '@assessment-management:cases.entities.assessment-case.fields.subject-entity-id.title',
                groupId: 'subject',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: { dataType: 'string', interface: { type: AXPWidgetsList.Editors.TextBox } },
                validations: [{ rule: 'required' }],
            },
        ],
        columns: [
            { name: 'title' },
            { name: 'questionnaireId', options: { dataPath: 'questionnaire.title' } },
            { name: 'statusId' },
            { name: 'subjectRef.type' },
            { name: 'subjectRef.id' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'subject', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'questionnaireId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'subjectRef.type', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'subjectRef.id', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'subject', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'questionnaireId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'subjectRef.type', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'subjectRef.id', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'subject', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'questionnaireId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'subjectRef.type', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'subjectRef.id', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    actions: [
                        ...entityMasterRecordActions(),
                        {
                            title: '@assessment-management:cases.actions.fill-assessment.title',
                            command: {
                                name: `${RootConfig.module.name}.${RootConfig.entities.assessmentCase.name}:Fill`,
                                options: {
                                    caseId: '{{ context.eval("id") }}',
                                    showAs: 'standalone',
                                },
                            },
                            priority: 'primary',
                            type: 'action',
                            icon: 'fa-light fa-clipboard-check',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions(),
                        {
                            title: '@assessment-management:cases.actions.fill-assessment.title',
                            command: {
                                name: `${RootConfig.module.name}.${RootConfig.entities.assessmentCase.name}:Fill`,
                                options: {
                                    caseId: '{{ context.eval("id") }}',
                                },
                            },
                            priority: 'primary',
                            type: 'action',
                            icon: 'fa-light fa-clipboard-check',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                    views: [createAllQueryView({ sorts: [{ name: 'updatedAt', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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