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

async function customerFactory(injector) {
    const dataService = injector.get(AXMCustomerManagementCustomerEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'customer';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.customer.name,
        title: RootConfig.entities.customer.title,
        icon: RootConfig.entities.customer.icon,
        formats: {
            individual: `@${i18n}:${entityName}.individual-title`,
            plural: `@${i18n}:${entityName}.plural-title`,
            displayName: 'Personal Information',
            searchResult: {
                title: '{{ party.displayName }}',
                description: RootConfig.module.title,
            },
        },
        plugins: [
            { name: 'identifier', options: { field: 'customerCode', rule: 'customer-code' } },
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'extra-properties' },
            { name: 'attachments', options: { accept: '.jpg,.jpeg,.png,.pdf', multiple: true, fileEditable: true } },
            { name: 'archive' },
            // { name: 'comments' },
        ],
        groups: [
            { id: 'basic-info', title: `@${i18n}:${entityName}.basic-info` },
            { id: 'classification', title: `@${i18n}:${entityName}.classification` },
            { id: 'account', title: `@${i18n}:${entityName}.account` },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', hidden: true, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'customerCode',
                title: `@${i18n}:${entityName}.customer-code`,
                groupId: 'basic-info',
                schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.text } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'customerTypeId',
                title: `@${i18n}:${entityName}.customer-type`,
                groupId: 'classification',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.customerType.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'customerType.id' },
                                { source: 'title', target: 'customerType.title' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
            },
            {
                name: 'segmentId',
                title: `@${i18n}:${entityName}.segment`,
                groupId: 'classification',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.customerSegment.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'segment.id' },
                                { source: 'title', target: 'segment.title' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
            },
            {
                name: 'status',
                title: '@general:terms.status.title',
                groupId: 'classification',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            dataSource: [
                                { id: 'active', title: 'Active' },
                                { id: 'inactive', title: 'Inactive' },
                                { id: 'blocked', title: 'Blocked' },
                                { id: 'archived', title: 'Archived' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
            },
            {
                name: 'since',
                title: `@${i18n}:${entityName}.since`,
                groupId: 'account',
                schema: { dataType: 'date', interface: { type: AXPWidgetsCatalog.dateTime } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
            },
            {
                name: 'isVip',
                title: `@${i18n}:${entityName}.is-vip`,
                groupId: 'account',
                schema: { dataType: 'boolean', interface: { type: AXPWidgetsCatalog.toggle } },
                options: { sort: { enabled: true }, filter: { advance: { enabled: true }, inline: { enabled: true } } },
            },
            {
                name: 'accountManagerId',
                title: `@${i18n}:${entityName}.account-manager`,
                groupId: 'account',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `HumanCapitalManagement.Employee`,
                            textField: 'party.displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'accountManager.id' },
                                { source: 'employeeCode', target: 'accountManager.employeeCode' },
                                { source: 'party.displayName', target: 'accountManager.displayName' },
                            ],
                        },
                    },
                },
                options: { sort: { enabled: false }, filter: { advance: { enabled: true }, inline: { enabled: false } } },
            },
            {
                name: 'notes',
                title: '@general:terms.common.notes',
                groupId: 'account',
                schema: { dataType: 'string', interface: { type: AXPWidgetsCatalog.largeText, options: { rows: 3 } } },
            },
        ],
        columns: [
            {
                name: 'party.displayName',
                title: '@general:terms.common.name',
                options: { width: '300px' },
                showAs: { type: AXPWidgetsCatalog.text },
            },
            { name: 'customerCode' },
            { name: 'customerTypeId', options: { dataPath: 'customerType.title' } },
            { name: 'segmentId', options: { dataPath: 'segment.title' } },
            { name: 'status' },
            { name: 'since' },
            { name: 'isVip' },
            { name: 'accountManagerId', options: { dataPath: 'accountManager.displayName' } },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.party.name}`,
                title: 'Contact Information',
                conditions: [
                    {
                        name: 'id',
                        operator: { type: 'equal' },
                        value: '{{ context.eval("partyId") }}',
                    },
                ],
                layout: {
                    type: 'merge-detail',
                    position: 'middle',
                },
                persistence: {
                    dataPath: 'party',
                    strategy: 'referenced',
                    idField: 'partyId',
                    map: {
                        displayName: '$parent.party.displayName',
                    },
                },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.opportunity.name}`,
                title: `@${i18n}:opportunity.plural-title`,
                columns: ['title', 'amount', 'stageId', 'expectedClose'],
                conditions: [{ name: 'customerId', operator: { type: 'equal' }, value: '{{ context.eval("id") }}' }],
                actions: [
                    {
                        title: '@general:actions.create.title',
                        command: { name: 'create-entity', options: { process: { redirect: false, canCreateNewOne: true } } },
                        priority: 'primary',
                        type: 'create',
                        scope: AXPEntityCommandScope.TypeLevel,
                    },
                ],
                layout: {
                    type: 'page-list',
                },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.activity.name}`,
                title: `@${i18n}:activity.plural-title`,
                columns: ['type', 'subject', 'dueDate', 'status'],
                conditions: [{ name: 'customerId', operator: { type: 'equal' }, value: '{{ context.eval("id") }}' }],
                actions: [
                    {
                        title: '@general:actions.create.title',
                        command: { name: 'create-entity', options: { process: { redirect: false, canCreateNewOne: true } } },
                        priority: 'primary',
                        type: 'create',
                        scope: AXPEntityCommandScope.TypeLevel,
                    },
                ],
                layout: {
                    type: 'page-list',
                },
            },
        ],
        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) => {
                    const res = await dataService.getOne(id);
                    return res;
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    const res = await dataService.query(e);
                    return res;
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }, { id: 'classification' }, { id: 'account' }],
                    properties: [
                        { name: 'customerCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'customerTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'segmentId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'since', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isVip', layout: { positions: { lg: { colSpan: 3 } } } },
                        { name: 'accountManagerId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'classification' }, { id: 'account' }],
                    properties: [
                        { name: 'customerCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'customerTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'segmentId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'since', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isVip', layout: { positions: { lg: { colSpan: 3 } } } },
                        { name: 'accountManagerId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{ party.displayName }}',
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'classification', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'account', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'customerCode', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'customerTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'segmentId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'since', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isVip', layout: { positions: { lg: { colSpan: 3 } } } },
                        { name: 'accountManagerId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'notes', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'party.displayName', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { customerFactory };
//# sourceMappingURL=acorex-modules-customer-management-customer.entity-DP7bXPKk.mjs.map
