import { AXPWidgetsList } from '@acorex/modules/common';
import { RootConfig as RootConfig$1 } from '@acorex/modules/supplier-management';
import { createAllQueryView } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { entityMasterCrudActions, entityMasterRecordActions, entityDetailsCrudActions, entityDetailsSimpleCondition } from '@acorex/platform/layout/entity';
import { RootConfig } from './acorex-modules-order-management.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Factory Function   ----
async function bulkBuyOrderFactory(injector) {
    const i18n = `${RootConfig.config.i18n}:bulk-buy-orders.entities.bulk-buy-order`;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.bulkBuyOrder.name,
        title: RootConfig.entities.bulkBuyOrder.title,
        icon: RootConfig.entities.bulkBuyOrder.icon,
        formats: {
            individual: RootConfig.entities.bulkBuyOrder.title,
            plural: RootConfig.entities.bulkBuyOrder.titlePlural,
            displayName: RootConfig.entities.bulkBuyOrder.title,
            searchResult: {
                title: '{{ orderNumber }}',
                description: '{{ title }}',
            },
        },
        plugins: [
            { name: 'identifier', options: { field: 'orderNumber', rule: 'order-management.bulk-buy-order-number' } },
            { name: 'history' },
            { name: 'compare' },
            {
                name: 'status',
                options: {
                    field: 'statusId',
                    definition: 'OrderManagement:Status:bulk-buy-order',
                },
            },
        ],
        groups: [
            { id: 'basic-info', title: `@${i18n}.groups.basic-info` },
            { id: 'order-details', title: `@${i18n}.groups.order-details` },
            { id: 'financial-info', title: `@${i18n}.groups.financial-info` },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'orderNumber',
                title: `@${i18n}.fields.order-number.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.order-number.placeholder`,
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'title',
                title: `@${i18n}.fields.title.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.title.placeholder`,
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'supplierId',
                title: `@${i18n}.fields.supplier.title`,
                groupId: 'order-details',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.supplier.name}`,
                            textField: 'person.displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'supplier.id' },
                                { source: 'person.displayName', target: 'supplier.displayName' },
                                { source: 'supplierCode', target: 'supplier.supplierCode' },
                            ],
                        },
                    },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'orderDate',
                title: `@${i18n}.fields.order-date.title`,
                groupId: 'order-details',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                        options: {
                            showTime: false,
                        },
                    },
                },
            },
            {
                name: 'deadlineDate',
                title: `@${i18n}.fields.deadline-date.title`,
                groupId: 'order-details',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                        options: {
                            showTime: false,
                        },
                    },
                },
            },
            {
                name: 'description',
                title: `@${i18n}.fields.description.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: false },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 4,
                        },
                    },
                },
            },
            {
                name: 'freightAmount',
                title: `@${i18n}.fields.freight-amount.title`,
                groupId: 'financial-info',
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: false } },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            decimals: 2,
                        },
                    },
                },
                validations: [
                    { rule: 'required' },
                ],
            },
        ],
        columns: [
            { name: 'orderNumber', options: { width: '150px' } },
            { name: 'title' },
            { name: 'supplierId', options: { dataPath: 'supplier.displayName' } },
            { name: 'orderDate' },
            { name: 'deadlineDate' },
            { name: 'freightAmount' },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.bulkBuyOrderItem.name}`,
                title: RootConfig.entities.bulkBuyOrderItem.titlePlural,
                columns: ['productId', 'size', 'quantityInOrder', 'price', 'unit', 'total'],
                conditions: [entityDetailsSimpleCondition('bulkBuyOrderId')],
                actions: [
                    ...entityDetailsCrudActions('bulkBuyOrderId'),
                ],
                layout: { type: 'tab-list' },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.memberOrder.name}`,
                title: RootConfig.entities.memberOrder.titlePlural,
                columns: ['memberId', 'productTotal', 'freightShare', 'totalOwing', 'statusId', 'paidDate'],
                conditions: [entityDetailsSimpleCondition('bulkBuyOrderId')],
                actions: [...entityDetailsCrudActions('bulkBuyOrderId')],
                layout: { type: 'page-list' },
            },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }, { id: 'order-details' }, { id: 'financial-info' }],
                    properties: [
                        { name: 'orderNumber', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'supplierId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'orderDate', layout: { positions: { lg: { colSpan: 6, } } } },
                        { name: 'deadlineDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'freightAmount', layout: { positions: { lg: { colSpan: 6, colStart: 1 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'order-details' }, { id: 'financial-info' }],
                    properties: [
                        { name: 'orderNumber', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'supplierId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'orderDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'deadlineDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'freightAmount', layout: { positions: { lg: { colSpan: 6, colStart: 1 } } } },
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [
                        { id: 'basic-info', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'order-details', order: 2, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'financial-info', order: 3, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'orderNumber', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'supplierId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'orderDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'deadlineDate', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'freightAmount', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'orderDate', dir: 'desc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { bulkBuyOrderFactory };
//# sourceMappingURL=acorex-modules-order-management-bulk-buy-order.entity-BMvkJRpA.mjs.map
