import { AXTranslationService } from '@acorex/core/translation';
import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { entityMasterCrudActions } from '@acorex/platform/layout/entity';
import { e as AXMPartyIdentifierService, R as RootConfig } from './acorex-modules-party-management-acorex-modules-party-management-BkRsPvsw.mjs';

//#region ----   Imports   ----
//#endregion
async function partyIdentifierFactory(injector) {
    const dataService = injector.get(AXMPartyIdentifierService);
    const i18n = RootConfig.config.i18n;
    const translateService = injector.get(AXTranslationService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.partyIdentifier.name,
        title: RootConfig.entities.partyIdentifier.title,
        icon: RootConfig.entities.partyIdentifier.icon,
        formats: {
            individual: RootConfig.entities.partyIdentifier.title,
            plural: RootConfig.entities.partyIdentifier.titlePlural,
            searchResult: {
                title: RootConfig.entities.partyIdentifier.title,
                description: '@party-management:party-identifier.search-result-description',
            },
        },
        plugins: [{ name: 'attachments' }],
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'validity', title: '@general:terms.validation.validity' },
        ],
        properties: [
            {
                name: 'partyId',
                title: '@party-management:party-identifier.properties.party.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.party.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.module.name}.${RootConfig.entities.partyIdentifierType.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: '@party-management:party-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: 'isPrimary',
                title: '@general:terms.status.states.is-primary',
                groupId: 'basic-info',
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                },
            },
            {
                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,
                    },
                },
            },
            {
                name: 'notes',
                title: '@general:terms.common.notes',
                groupId: 'metadata',
                options: { sort: { enabled: false }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 4,
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'typeId', options: { dataPath: 'type.title' } },
            { name: 'value' },
            { name: 'countryId', options: { dataPath: 'country.title' } },
            { name: 'isPrimary' },
            { name: 'validFrom' },
            { name: 'validTo' },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.party.name}`,
                title: '@party-management:party-identifier.related-entities.party.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{partyId}}',
                    },
                ],
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.partyIdentifierType.name}`,
                title: '@party-management:party-identifier.related-entities.type.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{typeId}}',
                    },
                ],
            },
        ],
        commands: {
            create: {
                execute: async (data) => {
                    const res = await dataService.insertOne(data);
                    return { id: res };
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        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: 'isPrimary',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 7,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 8,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 9,
                                    },
                                },
                            },
                        },
                    ],
                },
                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: 'isPrimary',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 7,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 8,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 9,
                                    },
                                },
                            },
                        },
                    ],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'validFrom', dir: 'desc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { partyIdentifierFactory };
//# sourceMappingURL=acorex-modules-party-management-party-identifier.entity-DWp9iYIa.mjs.map
