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

//#region ----   Imports   ----
//#endregion
async function partyRelationshipFactory(injector) {
    const dataService = injector.get(AXMPartyRelationshipService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.partyRelationship.name,
        title: RootConfig.entities.partyRelationship.title,
        icon: RootConfig.entities.partyRelationship.icon,
        formats: {
            individual: RootConfig.entities.partyRelationship.title,
            plural: RootConfig.entities.partyRelationship.titlePlural,
            searchResult: {
                title: RootConfig.entities.partyRelationship.title,
                description: '@party-management:party-relationship.search-result-description',
            },
        },
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'validity', title: '@general:terms.validation.validity' },
        ],
        properties: [
            {
                name: 'fromPartyId',
                title: '@party-management:party-relationship.properties.from-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,
                            expose: [
                                { source: 'id', target: 'fromParty.id' },
                                { source: 'title', target: 'fromParty.displayName' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'toPartyId',
                title: '@party-management:party-relationship.properties.to-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,
                            expose: [
                                { source: 'id', target: 'toParty.id' },
                                { source: 'displayName', target: 'toParty.displayName' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'typeId',
                title: '@party-management:party-relationship.properties.type.title',
                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.partyRelationshipType.name}`,
                            multiple: false,
                            expose: [
                                { source: 'id', target: 'type.id' },
                                { source: 'title', target: 'type.title' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                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: 'toPartyId', options: { dataPath: 'toParty.displayName' } },
            { name: 'typeId', options: { dataPath: 'type.title' } },
            { name: 'validFrom' },
            { name: 'validTo' },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.party.name}`,
                title: '@party-management:party-relationship.related-entities.from-party.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{fromPartyId}}',
                    },
                ],
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.partyRelationshipType.name}`,
                title: '@party-management:party-relationship.related-entities.type.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{typeId}}',
                    },
                ],
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.party.name}`,
                title: '@party-management:party-relationship.related-entities.to-party.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{toPartyId}}',
                    },
                ],
            },
        ],
        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',
                        },
                    ],
                    properties: [
                        {
                            name: 'toPartyId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'typeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'validity',
                        },
                    ],
                    properties: [
                        {
                            name: 'toPartyId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'typeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{type.title}} - {{fromParty.displayName}} → {{toParty.displayName}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            id: 'validity',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'toPartyId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'typeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validFrom',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 4,
                                    },
                                },
                            },
                        },
                        {
                            name: 'validTo',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 6,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'validFrom', dir: 'desc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { partyRelationshipFactory };
//# sourceMappingURL=acorex-modules-party-management-party-relationship.entity-DvgpmOkA.mjs.map
