import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXMContactMethodService, RootConfig } from './acorex-modules-contact-management.mjs';

async function contactMethodFactory(injector) {
    const dataService = injector.get(AXMContactMethodService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.contactMethod.name,
        title: RootConfig.entities.contactMethod.title,
        icon: RootConfig.entities.contactMethod.icon,
        formats: {
            individual: RootConfig.entities.contactMethod.title,
            plural: RootConfig.entities.contactMethod.titlePlural,
            searchResult: {
                title: '{{ value }}',
                description: '{{ methodType.name }}',
            },
        },
        plugins: [{ name: 'history' }, { name: 'lock' }, { name: 'compare' }, { name: 'primary' }, { name: 'archive' }],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'settings',
                title: '@general:terms.interface.settings',
            },
            {
                id: 'additional',
                title: '@general:terms.interface.additional-info',
            },
        ],
        properties: [
            {
                name: 'methodTypeId',
                title: '@general:terms.common.type',
                groupId: 'basic-info',
                options: {
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.contactMethodType.name}`,
                            textField: 'title',
                            valueField: 'name',
                            look: 'select',
                            placeholder: 'Select contact method type',
                            expose: [
                                { source: 'id', target: 'methodType.id' },
                                { source: 'title', target: 'methodType.title' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'value',
                title: '@general:terms.common.value',
                groupId: 'basic-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'Enter contact method value',
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'isVerified',
                title: '@general:terms.status.states.is-verified',
                groupId: 'settings',
                options: {
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                },
            },
            {
                name: 'notes',
                title: '@general:terms.common.notes',
                groupId: 'additional',
                options: {
                    filter: {
                        advance: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 3,
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'methodTypeId', options: { dataPath: 'methodType.title' } },
            { name: 'value' },
            { name: 'isVerified' },
            { name: 'notes' },
        ],
        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: 'settings',
                        },
                        {
                            id: 'additional',
                        },
                    ],
                    properties: [
                        {
                            name: 'methodTypeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'value',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'isVerified',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 3,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'settings',
                        },
                        {
                            id: 'additional',
                        },
                    ],
                    properties: [
                        {
                            name: 'methodTypeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'value',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'isVerified',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 3,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{value}}',
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'settings',
                        },
                        {
                            id: 'additional',
                        },
                    ],
                    properties: [
                        {
                            name: 'methodTypeId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 2,
                                    },
                                },
                            },
                        },
                        {
                            name: 'value',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                        order: 3,
                                    },
                                },
                            },
                        },
                        {
                            name: 'isVerified',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 3,
                                        order: 5,
                                    },
                                },
                            },
                        },
                        {
                            name: 'notes',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 6,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'value', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { contactMethodFactory };
//# sourceMappingURL=acorex-modules-contact-management-contact-method.entity-DM2VGu-z.mjs.map
