import { createAllQueryView } from '@acorex/platform/common';
import { AXPWidgetsList } from '@acorex/modules/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { RootConfig } from './acorex-modules-business-core.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function manufacturerFactory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.manufacturer.name,
        title: RootConfig.entities.manufacturer.title,
        icon: RootConfig.entities.manufacturer.icon,
        formats: {
            individual: RootConfig.entities.manufacturer.title,
            plural: RootConfig.entities.manufacturer.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: RootConfig.module.title,
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'clone' },
            { name: 'category', options: { appearance: { icon: true, color: true }, metaData: { enabled: true } } },
            { name: 'meta-data-form', options: { path: 'categoryIds' } },
            { name: 'archive' },
        ],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'contact-info',
                title: '@business-core:manufacturers.entities.manufacturer.groups.contact-info',
            },
        ],
        properties: [
            {
                name: 'code',
                title: '@general:terms.common.code',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: 'e.g., MFG-001',
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'title',
                title: '@general:terms.common.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'description',
                title: '@general:terms.common.description',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                        },
                    },
                },
            },
            {
                name: 'logo',
                title: '@business-core:manufacturers.entities.manufacturer.fields.logo.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Advanced.Avatar,
                        options: {
                            accept: ['.jpg', '.jpeg', '.png', '.svg'],
                            maxSize: 2048,
                        },
                    },
                },
            },
            {
                name: 'countryOfOrigin',
                title: '@business-core:manufacturers.entities.manufacturer.fields.country-of-origin.title',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                    },
                },
            },
            {
                name: 'website',
                title: '@business-core:manufacturers.entities.manufacturer.fields.website.title',
                groupId: 'contact-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: 'https://www.example.com',
                        },
                    },
                },
            },
            {
                name: 'contactEmail',
                title: '@business-core:manufacturers.entities.manufacturer.fields.contact-email.title',
                groupId: 'contact-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: 'contact@example.com',
                        },
                    },
                },
                validations: [
                    {
                        rule: 'email',
                    },
                ],
            },
            {
                name: 'contactPhone',
                title: '@business-core:manufacturers.entities.manufacturer.fields.contact-phone.title',
                groupId: 'contact-info',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: '+1-234-567-8900',
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'code' },
            { name: 'title' },
            { name: 'countryOfOrigin' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }, { id: 'contact-info' }],
                    properties: [
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'logo', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'countryOfOrigin', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'website', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'contactEmail', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'contactPhone', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'contact-info' }],
                    properties: [
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'logo', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'countryOfOrigin', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'website', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'contactEmail', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'contactPhone', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [{ id: 'basic-info' }, { id: 'contact-info' }],
                    properties: [
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'logo', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'countryOfOrigin', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'website', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'contactEmail', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'contactPhone', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { manufacturerFactory };
//# sourceMappingURL=acorex-modules-business-core-manufacturer.entity-DhyMx-nJ.mjs.map
