import { AXPWidgetsList } from '@acorex/modules/common';
import { createAllQueryView, AXPEntityQueryType } 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/party-management';
import { h as AXMCustomerManagementOpportunityEntityService, R as RootConfig } from './acorex-modules-customer-management-acorex-modules-customer-management-DJHmt24j.mjs';

async function opportunityFactory(injector) {
    const dataService = injector.get(AXMCustomerManagementOpportunityEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'opportunity';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.opportunity.name,
        title: RootConfig.entities.opportunity.title,
        icon: RootConfig.entities.opportunity.icon,
        formats: {
            individual: `t("${entityName}.individual-title", { scope: "${i18n}" })`,
            plural: `t("${entityName}.plural-title", { scope: "${i18n}" })`,
            searchResult: { title: '{{ title }}', description: RootConfig.module.title },
        },
        groups: [
            { id: 'basic-info', title: `t("${entityName}.basic-info", { scope: "${i18n}" })` },
            { id: 'relations', title: '@general:terms.relations' },
            { id: 'financial', title: '@general:terms.financial' },
            { id: 'classification', title: '@general:terms.classification' },
            { id: 'date', title: '@general:terms.datetime.date' },
        ],
        properties: [
            { name: 'title', title: `t("${entityName}.title", { scope: "${i18n}" })`, groupId: 'basic-info', schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.text } }, validations: [{ rule: 'required' }] },
            {
                name: 'customerId',
                title: `t("${entityName}.customer", { scope: "${i18n}" })`,
                groupId: 'relations',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.customer.name}`,
                            textField: 'party.displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'customer.{id}' },
                                { source: 'party.displayName', target: 'customer.{displayName}' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'contactId',
                title: `t("${entityName}.contact", { scope: "${i18n}" })`,
                groupId: 'relations',
                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}' },
                            ],
                        },
                    },
                },
            },
            { name: 'amount', title: `t("${entityName}.amount", { scope: "${i18n}" })`, groupId: 'financial', schema: { dataType: 'number', interface: { type: AXPWidgetsCatalog.number } } },
            { name: 'currency', title: `t("${entityName}.currency", { scope: "${i18n}" })`, groupId: 'financial', schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.text } } },
            { name: 'probability', title: `t("${entityName}.probability", { scope: "${i18n}" })`, groupId: 'financial', schema: { dataType: 'number', interface: { type: AXPWidgetsCatalog.number, options: { minValue: 0, maxValue: 100 } } } },
            { name: 'expectedClose', title: `t("${entityName}.expected-close", { scope: "${i18n}" })`, groupId: 'date', schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } } },
            {
                name: 'stageId',
                title: `t("${entityName}.stage", { scope: "${i18n}" })`,
                groupId: 'classification',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.opportunityStage.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'stage.{id}' },
                                { source: 'title', target: 'stage.{title}' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'pipelineId',
                title: `t("${entityName}.pipeline", { scope: "${i18n}" })`,
                groupId: 'classification',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.salesPipeline.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'pipeline.{id}' },
                                { source: 'title', target: 'pipeline.{title}' },
                            ],
                        },
                    },
                },
            },
        ],
        columns: [{ name: 'title' }, { name: 'customerId', options: { dataPath: 'customer.displayName' } }, { name: 'amount' }, { name: 'stageId', options: { dataPath: 'stage.title' } }, { name: 'expectedClose' }],
        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: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'customerId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'contactId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'amount', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'currency', layout: { positions: { lg: { colSpan: 2 } } } },
                        { name: 'probability', layout: { positions: { lg: { colSpan: 2 } } } },
                        { name: 'expectedClose', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'stageId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'pipelineId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'customerId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'contactId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'amount', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'currency', layout: { positions: { lg: { colSpan: 2 } } } },
                        { name: 'probability', layout: { positions: { lg: { colSpan: 2 } } } },
                        { name: 'expectedClose', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'stageId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'pipelineId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } }
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'customerId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'contactId', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'amount', layout: { positions: { lg: { colSpan: 4, order: 4 } } } },
                        { name: 'currency', layout: { positions: { lg: { colSpan: 2, order: 5 } } } },
                        { name: 'probability', layout: { positions: { lg: { colSpan: 2, order: 6 } } } },
                        { name: 'expectedClose', layout: { positions: { lg: { colSpan: 4, order: 7 } } } },
                        { name: 'stageId', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        { name: 'pipelineId', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                    ],
                    actions: []
                },
                list: { actions: [...entityMasterCrudActions()], views: [createAllQueryView({ sorts: [{ name: 'expectedClose', dir: 'asc' }] })] },
            },
        },
    };
    return entityDef;
}

export { opportunityFactory };
//# sourceMappingURL=acorex-modules-customer-management-opportunity.entity-ChNUMPQt.mjs.map
