import { AXTranslationService } from '@acorex/core/translation';
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-person-core.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function personIdentifierTypeFactory(injector) {
    const translateService = injector.get(AXTranslationService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.personIdentifierType.name,
        title: RootConfig.entities.personIdentifierType.title,
        icon: RootConfig.entities.personIdentifierType.icon,
        plugins: [{ name: 'archive' }],
        formats: {
            individual: RootConfig.entities.personIdentifierType.title,
            plural: RootConfig.entities.personIdentifierType.titlePlural,
            searchResult: {
                title: RootConfig.entities.personIdentifierType.title,
                description: '@person-core:person-identifier-types.entities.person-identifier-type.search-result-description',
            },
        },
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'validation', title: '@general:terms.validation.validation' },
        ],
        properties: [
            {
                name: 'id',
                title: '@general:terms.common.id',
                groupId: 'basic-info',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'title',
                title: '@general:terms.common.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: '@general:terms.common.description',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: { rows: 3 },
                    },
                },
            },
            {
                name: 'scope',
                title: '@person-core:person-identifier-types.entities.person-identifier-type.fields.scope',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'value',
                            textField: 'text',
                            dataSource: [
                                { value: 'global', text: await translateService.translateAsync('@person-core:person-identifier-types.entities.person-identifier-type.fields.scope-options.global') },
                                { value: 'national', text: await translateService.translateAsync('@person-core:person-identifier-types.entities.person-identifier-type.fields.scope-options.national') },
                                { value: 'regional', text: await translateService.translateAsync('@person-core:person-identifier-types.entities.person-identifier-type.fields.scope-options.regional') },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'formatRegex',
                title: '@general:terms.validation.regex',
                groupId: 'validation',
                options: { sort: { enabled: false }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: {
                    dataType: 'string',
                    interface: { type: AXPWidgetsList.Editors.TextBox },
                },
            },
            {
                name: 'minLength',
                title: '@general:terms.validation.min-length',
                groupId: 'validation',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: { minValue: 1, maxValue: 100 },
                    },
                },
            },
            {
                name: 'maxLength',
                title: '@general:terms.validation.max-length',
                groupId: 'validation',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: { minValue: 1, maxValue: 1000 },
                    },
                },
            },
            {
                name: 'isUnique',
                title: '@general:terms.status.states.is-unique',
                groupId: 'validation',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'boolean',
                    interface: { type: AXPWidgetsList.Editors.ToggleSwitch },
                },
            },
        ],
        columns: [
            { name: 'title', options: { width: '200px', order: 1 } },
            { name: 'scope', options: { width: '120px', order: 2 } },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }, { id: 'validation' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'scope', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'formatRegex', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'minLength', layout: { positions: { lg: { colSpan: 3, order: 5 } } } },
                        { name: 'maxLength', layout: { positions: { lg: { colSpan: 3, order: 6 } } } },
                        { name: 'isUnique', layout: { positions: { lg: { colSpan: 3, order: 7 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'validation' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'scope', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'formatRegex', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'minLength', layout: { positions: { lg: { colSpan: 3, order: 6 } } } },
                        { name: 'maxLength', layout: { positions: { lg: { colSpan: 3, order: 7 } } } },
                        { name: 'isUnique', layout: { positions: { lg: { colSpan: 3, order: 8 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [{ id: 'basic-info' }, { id: 'validation' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'scope', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'formatRegex', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'minLength', layout: { positions: { lg: { colSpan: 3, order: 6 } } } },
                        { name: 'maxLength', layout: { positions: { lg: { colSpan: 3, order: 7 } } } },
                        { name: 'isUnique', layout: { positions: { lg: { colSpan: 3, order: 8 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { personIdentifierTypeFactory };
//# sourceMappingURL=acorex-modules-person-core-person-identifier-type.entity-BIFiRZ2d.mjs.map
