import { createAllQueryView } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { entityMasterCrudActions, entityMasterRecordActions } 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 personRelationshipFactory(injector) {
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.personRelationship.name,
        title: RootConfig.entities.personRelationship.title,
        icon: RootConfig.entities.personRelationship.icon,
        formats: {
            individual: RootConfig.entities.personRelationship.title,
            plural: RootConfig.entities.personRelationship.titlePlural,
            searchResult: {
                title: RootConfig.entities.personRelationship.title,
                description: '@person-management:person-relationship.search-result-description',
            },
        },
        groups: [
            { id: 'basic-info', title: '@general:terms.interface.basic-info' },
            { id: 'validity', title: '@general:terms.validation.validity' },
        ],
        properties: [
            {
                name: 'fromPersonId',
                title: '@person-management:person-relationship.properties.from-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,
                            expose: [
                                { source: 'id', target: 'fromPerson.id' },
                                { source: 'title', target: 'fromPerson.displayName' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'toPersonId',
                title: '@person-management:person-relationship.properties.to-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,
                            textField: "displayName",
                            columns: ["displayName", "phones", "emails"],
                            expose: [
                                { source: 'id', target: 'toPerson.id' },
                                { source: 'displayName', target: 'toPerson.displayName' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'typeId',
                title: '@person-management:person-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$1.module.name}.${RootConfig$1.entities.personRelationshipType.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: 'toPersonId', options: { dataPath: 'toPerson.displayName' } },
            { name: 'typeId', options: { dataPath: 'type.title' } },
            { name: 'validFrom' },
            { name: 'validTo' },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.person.name}`,
                title: '@person-management:person-relationship.related-entities.from-person.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{fromPersonId}}',
                    },
                ],
            },
            {
                entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.personRelationshipType.name}`,
                title: '@person-management:person-relationship.related-entities.type.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{typeId}}',
                    },
                ],
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.person.name}`,
                title: '@person-management:person-relationship.related-entities.to-person.title',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{toPersonId}}',
                    },
                ],
            },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'validity',
                        },
                    ],
                    properties: [
                        {
                            name: 'toPersonId',
                            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: 'toPersonId',
                            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}} - {{fromPerson.displayName}} → {{toPerson.displayName}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            id: 'validity',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'toPersonId',
                            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 { personRelationshipFactory };
//# sourceMappingURL=acorex-modules-person-management-person-relationship.entity-DbcXasEe.mjs.map
