import { RootConfig as RootConfig$3 } from '@acorex/modules/business-core';
import { RootConfig as RootConfig$1 } from '@acorex/modules/financial-core';
import { RootConfig as RootConfig$2 } from '@acorex/modules/measurement-core';
import { createAllQueryView } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions, entityDetailsCrudActions, entityDetailsSimpleCondition } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { RootConfig } from './acorex-modules-product-catalog.mjs';

//#region ----   Imports   ----
//#endregion
async function productFactory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.product.name,
        title: RootConfig.entities.product.title,
        icon: RootConfig.entities.product.icon,
        formats: {
            individual: RootConfig.entities.product.title,
            plural: RootConfig.entities.product.titlePlural,
            displayName: RootConfig.entities.product.title,
            searchResult: {
                title: '{{ title }} ({{ code }})',
                description: RootConfig.module.title,
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'clone' },
            {
                name: 'category',
                options: {
                    appearance: { icon: true, color: true },
                    metaData: { enabled: true },
                    // readonly: true,
                    // categoryEntity: "BusinessCore.ManufacturerCategory"
                }
            },
            {
                name: 'meta-data-form',
                options: {
                    path: 'categoryIds',
                    title: '@product-catalog:products.entities.product.components.meta-data-form.title',
                },
            },
            {
                name: 'status',
                options: {
                    field: 'statusId',
                    definition: 'product-catalog.status.product',
                },
            },
            { name: 'tags' },
            { name: 'notes' },
            {
                name: 'computed-property',
                options: {
                    fields: [
                        {
                            name: 'rating',
                            title: '@product-catalog:products.entities.product.fields.rating.title',
                            value: '{{ context.eval("basePrice") ? Math.min(5, Math.max(1, Math.round(context.eval("basePrice") / 100))) : 0 }}',
                            group: {
                                id: 'basic-info',
                                title: '@general:terms.interface.basic-info',
                            },
                            layout: {
                                order: 5,
                                colSpan: 6,
                            },
                            showAs: {
                                type: 'rate-picker-editor',
                                options: {
                                    max: 5,
                                    readonly: true,
                                },
                            },
                        },
                    ],
                },
            },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.productSku.name}`,
                title: RootConfig.entities.productSku.titlePlural,
                columns: ['sku', 'variantName', 'price', 'isDisabled'],
                conditions: [
                    {
                        name: 'productId',
                        operator: { type: 'equal' },
                        value: '{{ context.eval("id") }}',
                    },
                ],
            },
            {
                entity: `ProcurementManagement.SupplierProduct`,
                title: '@procurement-management:supplier-products.terms.suppliers',
                columns: [
                    'supplier.displayName',
                    'product.code',
                    'product.title',
                    'unitPrice',
                    'currency.code',
                    'priority',
                    'leadTimeDays',
                ],
                conditions: [entityDetailsSimpleCondition('productId')],
                actions: [...entityDetailsCrudActions('productId')],
                layout: { type: 'page-list' },
            },
        ],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'sourcing',
                title: '@product-catalog:products.entities.product.groups.sourcing',
            },
            {
                id: 'financial',
                title: '@product-catalog:products.entities.product.groups.financial-info',
            },
            {
                id: 'measurement',
                title: '@product-catalog:products.entities.product.groups.measurement-info',
            },
            {
                id: 'media',
                title: '@product-catalog:products.entities.product.groups.media',
            },
        ],
        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: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'e.g., PROD-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: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'shortName',
                title: '@general:terms.common.short-name',
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
            },
            {
                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: AXPWidgetsCatalog.largeText,
                        options: {
                            rows: 3,
                        },
                    },
                },
            },
            {
                name: 'brandId',
                title: '@product-catalog:products.entities.product.fields.brand.title',
                groupId: 'sourcing',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.brand.name}`,
                            multiple: false,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'brand.id' },
                                { source: 'title', target: 'brand.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'taxClassId',
                title: '@product-catalog:products.entities.product.fields.tax-class.title',
                groupId: 'financial',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.taxClass.name}`,
                            multiple: false,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'taxClass.id' },
                                { source: 'title', target: 'taxClass.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'baseCurrencyId',
                title: '@product-catalog:products.entities.product.fields.base-currency.title',
                groupId: 'financial',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.currency.name}`,
                            multiple: false,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'baseCurrency.id' },
                                { source: 'code', target: 'baseCurrency.code' },
                                { source: 'symbol', target: 'baseCurrency.symbol' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'basePrice',
                title: '@product-catalog:products.entities.product.fields.base-price.title',
                groupId: 'financial',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            min: 0,
                            step: 0.01,
                        },
                    },
                },
            },
            {
                name: 'baseUnitOfMeasureId',
                title: '@product-catalog:products.entities.product.fields.base-unit.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$2.module.name}.${RootConfig$2.entities.unitOfMeasure.name}`,
                            multiple: false,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'baseUnitOfMeasure.id' },
                                { source: 'code', target: 'baseUnitOfMeasure.code' },
                                { source: 'title', target: 'baseUnitOfMeasure.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'weight',
                title: '@product-catalog:products.entities.product.fields.weight.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            min: 0,
                            step: 0.01,
                        },
                    },
                },
            },
            {
                name: 'weightUnitId',
                title: '@product-catalog:products.entities.product.fields.weight-unit.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$2.module.name}.${RootConfig$2.entities.unitOfMeasure.name}`,
                            multiple: false,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'weightUnit.id' },
                                { source: 'code', target: 'weightUnit.code' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'length',
                title: '@product-catalog:products.entities.product.fields.length.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            min: 0,
                            step: 0.01,
                        },
                    },
                },
            },
            {
                name: 'width',
                title: '@product-catalog:products.entities.product.fields.width.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            min: 0,
                            step: 0.01,
                        },
                    },
                },
            },
            {
                name: 'height',
                title: '@product-catalog:products.entities.product.fields.height.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            min: 0,
                            step: 0.01,
                        },
                    },
                },
            },
            {
                name: 'dimensionUnitId',
                title: '@product-catalog:products.entities.product.fields.dimension-unit.title',
                groupId: 'measurement',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$2.module.name}.${RootConfig$2.entities.unitOfMeasure.name}`,
                            multiple: false,
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'dimensionUnit.id' },
                                { source: 'code', target: 'dimensionUnit.code' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'manufacturerId',
                title: '@product-catalog:products.entities.product.fields.manufacturer.title',
                groupId: 'sourcing',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$3.module.name}.${RootConfig$3.entities.manufacturer.name}`,
                            multiple: false,
                            expose: [
                                { source: 'id', target: 'manufacturer.id' },
                                { source: 'title', target: 'manufacturer.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'images',
                title: '@product-catalog:products.entities.product.fields.images.title',
                groupId: 'media',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'array',
                    interface: {
                        type: AXPWidgetsCatalog.gallery,
                    },
                },
            },
        ],
        columns: [
            { name: 'code' },
            { name: 'title' },
            { name: 'brandId', options: { dataPath: 'brand.title' } },
            { name: 'basePrice' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'sourcing' },
                        { id: 'financial' },
                        { id: 'measurement' },
                        { id: 'media' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'shortName', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Sourcing
                        { name: 'brandId', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'manufacturerId', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        // Financial
                        { name: 'taxClassId', layout: { positions: { lg: { colSpan: 4, order: 8 } } } },
                        { name: 'baseCurrencyId', layout: { positions: { lg: { colSpan: 4, order: 9 } } } },
                        { name: 'basePrice', layout: { positions: { lg: { colSpan: 4, order: 10 } } } },
                        // Measurement
                        { name: 'baseUnitOfMeasureId', layout: { positions: { lg: { colSpan: 6, order: 11 } } } },
                        { name: 'weight', layout: { positions: { lg: { colSpan: 3, order: 12 } } } },
                        { name: 'weightUnitId', layout: { positions: { lg: { colSpan: 3, order: 13 } } } },
                        { name: 'length', layout: { positions: { lg: { colSpan: 2, order: 14 } } } },
                        { name: 'width', layout: { positions: { lg: { colSpan: 2, order: 15 } } } },
                        { name: 'height', layout: { positions: { lg: { colSpan: 2, order: 16 } } } },
                        { name: 'dimensionUnitId', layout: { positions: { lg: { colSpan: 6, order: 17 } } } },
                        // Media
                        { name: 'images', layout: { positions: { lg: { colSpan: 12, order: 18 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'sourcing' },
                        { id: 'financial' },
                        { id: 'measurement' },
                        { id: 'media' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'shortName', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Sourcing
                        { name: 'brandId', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'manufacturerId', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        // Financial
                        { name: 'taxClassId', layout: { positions: { lg: { colSpan: 4, order: 8 } } } },
                        { name: 'baseCurrencyId', layout: { positions: { lg: { colSpan: 4, order: 9 } } } },
                        { name: 'basePrice', layout: { positions: { lg: { colSpan: 4, order: 10 } } } },
                        // Measurement
                        { name: 'baseUnitOfMeasureId', layout: { positions: { lg: { colSpan: 6, order: 11 } } } },
                        { name: 'weight', layout: { positions: { lg: { colSpan: 3, order: 12 } } } },
                        { name: 'weightUnitId', layout: { positions: { lg: { colSpan: 3, order: 13 } } } },
                        { name: 'length', layout: { positions: { lg: { colSpan: 2, order: 14 } } } },
                        { name: 'width', layout: { positions: { lg: { colSpan: 2, order: 15 } } } },
                        { name: 'height', layout: { positions: { lg: { colSpan: 2, order: 16 } } } },
                        { name: 'dimensionUnitId', layout: { positions: { lg: { colSpan: 6, order: 17 } } } },
                        // Media
                        { name: 'images', layout: { positions: { lg: { colSpan: 12, order: 18 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info' },
                        { id: 'sourcing' },
                        { id: 'financial' },
                        { id: 'measurement' },
                        { id: 'media' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'shortName', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Sourcing
                        { name: 'brandId', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'manufacturerId', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        // Financial
                        { name: 'taxClassId', layout: { positions: { lg: { colSpan: 4, order: 8 } } } },
                        { name: 'baseCurrencyId', layout: { positions: { lg: { colSpan: 4, order: 9 } } } },
                        { name: 'basePrice', layout: { positions: { lg: { colSpan: 4, order: 10 } } } },
                        // Measurement
                        { name: 'baseUnitOfMeasureId', layout: { positions: { lg: { colSpan: 6, order: 11 } } } },
                        { name: 'weight', layout: { positions: { lg: { colSpan: 3, order: 12 } } } },
                        { name: 'weightUnitId', layout: { positions: { lg: { colSpan: 3, order: 13 } } } },
                        { name: 'length', layout: { positions: { lg: { colSpan: 2, order: 14 } } } },
                        { name: 'width', layout: { positions: { lg: { colSpan: 2, order: 15 } } } },
                        { name: 'height', layout: { positions: { lg: { colSpan: 2, order: 16 } } } },
                        { name: 'dimensionUnitId', layout: { positions: { lg: { colSpan: 6, order: 17 } } } },
                        // Media
                        { name: 'images', layout: { label: { visible: false }, positions: { lg: { colSpan: 12, order: 18 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { productFactory };
//# sourceMappingURL=acorex-modules-product-catalog-product.entity-CVW7-ye7.mjs.map
