import { AXTranslationService } from '@acorex/core/translation';
import { createAllQueryView } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { entityMasterCrudActions } from '@acorex/platform/layout/entity';
import { RootConfig as RootConfig$1 } from '@acorex/modules/person-core';
import { RootConfig } from './acorex-modules-person-management.mjs';

//#region ----   Imports   ----
//#endregion
async function personIdentifierFactory(injector) {
    const i18n = RootConfig.config.i18n;
    const translateService = injector.get(AXTranslationService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.personIdentifier.name,
        title: RootConfig.entities.personIdentifier.title,
        icon: RootConfig.entities.personIdentifier.icon,
        formats: {
            individual: RootConfig.entities.personIdentifier.title,
            plural: RootConfig.entities.personIdentifier.titlePlural,
            searchResult: {
                title: RootConfig.entities.personIdentifier.title,
                description: '@person-management:person-identifier.search-result-description',
            },
        },
        plugins: [{ name: 'notes' }, { name: 'attachments' }],
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'validity', title: '@general:terms.validation.validity' },
        ],
        properties: [
            {
                name: 'personId',
                title: '@person-management:person-identifier.properties.person.title',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.person.name}`,
                            multiple: false,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'typeId',
                title: '@general:terms.common.type',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            look: 'select',
                            entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.personIdentifierType.name}`,
                            expose: [
                                { source: 'id', target: 'type.id' },
                                { source: 'title', target: 'type.title' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'value',
                title: '@general:terms.common.value',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'countryId',
                title: '@general:terms.geography.country',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: 'LocationManagement.GeographicRegion',
                            look: 'select',
                            allowClear: true,
                            expose: [
                                { source: 'id', target: 'country.id' },
                                { source: 'title', target: 'country.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'issuer',
                title: '@person-management:person-identifier.properties.issuer.title',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
            },
            {
                name: 'validFrom',
                title: '@general:terms.validation.valid-from',
                groupId: 'validity',
                options: { sort: { enabled: true }, filter: { advance: { enabled: false }, inline: { enabled: false } } },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                },
            },
            {
                name: 'validTo',
                title: '@general:terms.validation.valid-to',
                groupId: 'validity',
                options: { sort: { enabled: true }, filter: { advance: { enabled: false }, inline: { enabled: false } } },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                },
            },
        ],
        columns: [
            { name: 'typeId', options: { dataPath: 'type.title' } },
            { name: 'value' },
            { name: 'countryId', options: { dataPath: 'country.title' } },
            { name: 'validFrom' },
            { name: 'validTo' },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.person.name}`,
                title: '@person-management:person-identifier.related-entities.person.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{personId}}',
                    },
                ],
            },
            {
                entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.personIdentifierType.name}`,
                title: '@person-management:person-identifier.related-entities.type.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{typeId}}',
                    },
                ],
            },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'validity',
                        },
                        {
                            id: 'metadata',
                        },
                    ],
                    properties: [
                        {
                            name: 'typeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'value',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'countryId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'issuer',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 7,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 8,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'validity',
                        },
                        {
                            id: 'metadata',
                        },
                    ],
                    properties: [
                        {
                            name: 'typeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'value',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'countryId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'issuer',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 7,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 8,
                                    },
                                },
                            },
                        },
                    ],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'validFrom', dir: 'desc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { personIdentifierFactory };
//# sourceMappingURL=acorex-modules-person-management-person-identifier.entity-HBmiUahC.mjs.map
