import { AXPWidgetsList } from '@acorex/modules/common';
import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { RootConfig as RootConfig$1 } from '@acorex/modules/party-management';
import { j as AXMCustomerManagementDealContactRoleEntityService, R as RootConfig } from './acorex-modules-customer-management-acorex-modules-customer-management-DJHmt24j.mjs';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';

async function dealContactRoleFactory(injector) {
    const dataService = injector.get(AXMCustomerManagementDealContactRoleEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'deal-contact-role';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.dealContactRole.name,
        title: RootConfig.entities.dealContactRole.title,
        icon: RootConfig.entities.dealContactRole.icon,
        formats: {
            individual: `t("${entityName}.individual-title", { scope: "${i18n}" })`,
            plural: `t("${entityName}.plural-title", { scope: "${i18n}" })`,
            searchResult: { title: '{{ role }}', description: RootConfig.module.title },
        },
        groups: [{ id: 'basic-info', title: `t("${entityName}.basic-info", { scope: "${i18n}" })` }],
        properties: [
            {
                name: 'opportunityId',
                title: `t("${entityName}.opportunity", { scope: "${i18n}" })`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.opportunity.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'opportunity.{id}' },
                                { source: 'title', target: 'opportunity.{title}' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'contactId',
                title: `t("${entityName}.contact", { scope: "${i18n}" })`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.party.name}`,
                            textField: 'displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'contact.{id}' },
                                { source: 'displayName', target: 'contact.{displayName}' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'role',
                title: `t("${entityName}.role", { scope: "${i18n}" })`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                { id: 'decision-maker', title: 'Decision Maker' },
                                { id: 'influencer', title: 'Influencer' },
                                { id: 'economic-buyer', title: 'Economic Buyer' },
                                { id: 'user', title: 'User' },
                                { id: 'other', title: 'Other' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
        ],
        columns: [
            { name: 'opportunityId', options: { dataPath: 'opportunity.title' } },
            { name: 'contactId', options: { dataPath: 'contact.displayName' } },
            { name: 'role' },
        ],
        commands: {
            create: { execute: async (data) => ({ id: await dataService.insertOne(data) }) },
            delete: { execute: async (id) => await dataService.deleteOne(id) },
            update: { execute: async (data) => await dataService.updateOne(data.id, data) },
        },
        queries: {
            byKey: { execute: async (id) => await dataService.getOne(id), type: AXPEntityQueryType.Single },
            list: { execute: async (e) => await dataService.query(e), type: AXPEntityQueryType.List },
        },
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }],
                    properties: [
                        { name: 'opportunityId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'contactId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'role', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }],
                    properties: [
                        { name: 'opportunityId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'contactId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'role', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{role}}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }
                    ],
                    properties: [
                        { name: 'opportunityId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'contactId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'role', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                    ],
                    actions: [...entityMasterRecordActions()]
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'role', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { dealContactRoleFactory };
//# sourceMappingURL=acorex-modules-customer-management-deal-contact-role.entity-BvGlBK6A.mjs.map
