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

//#region ----   Imports   ----
//#endregion
async function productSkuFactory(injector) {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.productSku.name,
        title: RootConfig.entities.productSku.title,
        icon: RootConfig.entities.productSku.icon,
        formats: {
            individual: RootConfig.entities.productSku.title,
            plural: RootConfig.entities.productSku.titlePlural,
            searchResult: {
                title: '{{ sku }} - {{ variantName }}',
                description: '{{ product.title }}',
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'default' },
            { name: 'compare' },
            { name: 'clone' },
            { name: 'archive' },
            { name: 'notes' },
        ],
        groups: [
            {
                id: 'basic-info',
                title: '@general:terms.interface.basic-info',
            },
            {
                id: 'identifiers',
                title: '@product-catalog:skus.entities.product-sku.groups.identifiers',
            },
            {
                id: 'pricing',
                title: '@product-catalog:skus.entities.product-sku.groups.pricing',
            },
            {
                id: 'measurement',
                title: '@product-catalog:skus.entities.product-sku.groups.measurement-info',
            },
            {
                id: 'media',
                title: '@product-catalog:skus.entities.product-sku.groups.media',
            },
            {
                id: 'settings',
                title: '@general:terms.interface.settings',
            },
        ],
        properties: [
            {
                name: 'sku',
                title: '@product-catalog:skus.entities.product-sku.fields.sku.title',
                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., SKU-001',
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'productId',
                title: '@product-catalog:skus.entities.product-sku.fields.product.title',
                groupId: 'basic-info',
                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.product.name}`,
                            multiple: false,
                            expose: [
                                { source: 'id', target: 'product.id' },
                                { source: 'title', target: 'product.title' },
                                { source: 'code', target: 'product.code' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'variantName',
                title: '@product-catalog:skus.entities.product-sku.fields.variant-name.title',
                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., Red/Large, 500ml',
                        },
                    },
                },
            },
            {
                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: 2,
                        },
                    },
                },
            },
            {
                name: 'barcode',
                title: '@product-catalog:skus.entities.product-sku.fields.barcode.title',
                groupId: 'identifiers',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
            },
            {
                name: 'qrCode',
                title: '@product-catalog:skus.entities.product-sku.fields.qr-code.title',
                groupId: 'identifiers',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
            },
            {
                name: 'ean',
                title: '@product-catalog:skus.entities.product-sku.fields.ean.title',
                groupId: 'identifiers',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'EAN-13',
                        },
                    },
                },
            },
            {
                name: 'upc',
                title: '@product-catalog:skus.entities.product-sku.fields.upc.title',
                groupId: 'identifiers',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: 'UPC-A',
                        },
                    },
                },
            },
            {
                name: 'price',
                title: '@product-catalog:skus.entities.product-sku.fields.price.title',
                groupId: 'pricing',
                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: 'compareAtPrice',
                title: '@product-catalog:skus.entities.product-sku.fields.compare-at-price.title',
                groupId: 'pricing',
                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: 'costPrice',
                title: '@product-catalog:skus.entities.product-sku.fields.cost-price.title',
                groupId: 'pricing',
                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: 'weight',
                title: '@product-catalog:skus.entities.product-sku.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:skus.entities.product-sku.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$1.module.name}.${RootConfig$1.entities.unitOfMeasure.name}`,
                            multiple: false,
                            expose: [
                                { source: 'id', target: 'weightUnit.id' },
                                { source: 'code', target: 'weightUnit.code' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'length',
                title: '@product-catalog:skus.entities.product-sku.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:skus.entities.product-sku.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:skus.entities.product-sku.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:skus.entities.product-sku.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$1.module.name}.${RootConfig$1.entities.unitOfMeasure.name}`,
                            multiple: false,
                            expose: [
                                { source: 'id', target: 'dimensionUnit.id' },
                                { source: 'code', target: 'dimensionUnit.code' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'images',
                title: '@product-catalog:skus.entities.product-sku.fields.images.title',
                groupId: 'media',
                options: {
                    sort: { enabled: false },
                    filter: {
                        advance: { enabled: false },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'array',
                    interface: {
                        type: AXPWidgetsCatalog.fileUploader,
                        options: {
                            accept: ['.jpg', '.jpeg', '.png', '.webp'],
                            maxSize: 5120,
                            multiple: true,
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'sku' },
            { name: 'productId', options: { dataPath: 'product.title' } },
            { name: 'variantName' },
            { name: 'price' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'identifiers' },
                        { id: 'pricing' },
                        { id: 'measurement' },
                        { id: 'media' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'sku', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'productId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'variantName', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Identifiers
                        { name: 'barcode', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'qrCode', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'ean', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'upc', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        // Pricing
                        { name: 'price', layout: { positions: { lg: { colSpan: 4, order: 9 } } } },
                        { name: 'compareAtPrice', layout: { positions: { lg: { colSpan: 4, order: 10 } } } },
                        { name: 'costPrice', layout: { positions: { lg: { colSpan: 4, order: 11 } } } },
                        // Measurement
                        { 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: 'identifiers' },
                        { id: 'pricing' },
                        { id: 'measurement' },
                        { id: 'media' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'sku', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'productId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'variantName', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Identifiers
                        { name: 'barcode', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'qrCode', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'ean', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'upc', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        // Pricing
                        { name: 'price', layout: { positions: { lg: { colSpan: 4, order: 9 } } } },
                        { name: 'compareAtPrice', layout: { positions: { lg: { colSpan: 4, order: 10 } } } },
                        { name: 'costPrice', layout: { positions: { lg: { colSpan: 4, order: 11 } } } },
                        // Measurement
                        { 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: '{{sku}}',
                    sections: [
                        { id: 'basic-info' },
                        { id: 'identifiers' },
                        { id: 'pricing' },
                        { id: 'measurement' },
                        { id: 'media' },
                        { id: 'settings' },
                    ],
                    properties: [
                        // Basic Info
                        { name: 'sku', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'productId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'variantName', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        // Identifiers
                        { name: 'barcode', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'qrCode', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'ean', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'upc', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        // Pricing
                        { name: 'price', layout: { positions: { lg: { colSpan: 4, order: 9 } } } },
                        { name: 'compareAtPrice', layout: { positions: { lg: { colSpan: 4, order: 10 } } } },
                        { name: 'costPrice', layout: { positions: { lg: { colSpan: 4, order: 11 } } } },
                        // Measurement
                        { 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 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'sku', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

export { productSkuFactory };
//# sourceMappingURL=acorex-modules-product-catalog-product-sku.entity-BNJHLs-b.mjs.map
