import * as i0 from '@angular/core';
import { Injectable, inject, Injector, NgModule } from '@angular/core';
import { AXP_MODULE_MANIFEST_PROVIDER } from '@acorex/platform/core';
import { AXPEntityService, AXP_ENTITY_DEFINITION_LOADER, entityMasterCrudActions, entityMasterDeleteAction } from '@acorex/platform/layout/entity';
import { AXP_MENU_PROVIDER, createAllQueryView } from '@acorex/platform/common';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { AXTranslationService } from '@acorex/core/translation';
import { AXPCommonMenuKeys, AXPWidgetsList } from '@acorex/modules/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { RootConfig as RootConfig$1 } from '@acorex/modules/supplier-management';
import { RootConfig as RootConfig$2 } from '@acorex/modules/product-catalog';
import { RootConfig as RootConfig$3 } from '@acorex/modules/financial-core';

const config = {
    i18n: 'procurement-management',
    module: 'ProcurementManagement',
};
const RootConfig = {
    config,
    module: {
        route: 'procurement-management',
        name: config.module,
        title: `@${config.i18n}:module.title`,
        icon: 'fa-light fa-shopping-cart',
    },
    entities: {
        supplierProduct: {
            name: 'SupplierProduct',
            source: `${config.module}.SupplierProduct`,
            title: `@${config.i18n}:supplier-products.entities.supplier-product.title`,
            titlePlural: `@${config.i18n}:supplier-products.entities.supplier-product.plural`,
            icon: 'fa-light fa-link',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Procurement Management Module Manifest.
 * Defines module metadata, features, and provider references.
 */
const ProcurementManagementManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
    // Module dependencies
    dependencies: ['SupplierManagement', 'ProductCatalog'],
};
//#endregion

class AXMProcurementManagementPermissionDefinitionProvider {
    constructor(injector) {
        this.injector = injector;
    }
    get translateService() {
        return this.injector.get(AXTranslationService);
    }
    async define(context) {
        const trans = async (key) => await this.translateService.translateAsync(`@${RootConfig.config.i18n}:${key}`);
        const supplierProductsKey = `${RootConfig.module.name}.SupplierProducts`;
        context
            .addGroup(RootConfig.module.name, await trans('module.title'))
            .addPermission(supplierProductsKey, await trans('supplier-products.permissions.supplier-products.title'))
            .addChild(`${supplierProductsKey}.View`, await trans('supplier-products.permissions.supplier-products.actions.view.title'))
            .addChild(`${supplierProductsKey}.Create`, await trans('supplier-products.permissions.supplier-products.actions.create.title'))
            .addChild(`${supplierProductsKey}.Edit`, await trans('supplier-products.permissions.supplier-products.actions.edit.title'))
            .addChild(`${supplierProductsKey}.Delete`, await trans('supplier-products.permissions.supplier-products.actions.delete.title'))
            .addChild(`${supplierProductsKey}.Manage`, await trans('supplier-products.permissions.supplier-products.actions.manage.title'))
            .endPermission()
            .endGroup();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementPermissionDefinitionProvider, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementPermissionDefinitionProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementPermissionDefinitionProvider, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i0.Injector }] });

class AXMProcurementManagementMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        context.find(AXPCommonMenuKeys.Commerce).addItems([
            {
                name: `${RootConfig.module.route}:supplier-products`,
                text: `@${RootConfig.config.i18n}:supplier-products.entities.supplier-product.plural`,
                path: this.entityService.createPath(module.name, RootConfig.entities.supplierProduct.name),
                icon: RootConfig.entities.supplierProduct.icon,
                priority: 7,
                policy: {
                    features: [module.name],
                },
            },
        ]);
    }
}

class AXMProcurementManagementEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    preload() {
        const module = RootConfig.module.name;
        return Array.from(Object.values(RootConfig.entities)).map((entity) => ({
            module: module,
            entity: entity.name,
        }));
    }
    async get(moduleName, entityName) {
        if (moduleName == RootConfig.module.name) {
            switch (entityName) {
                case RootConfig.entities.supplierProduct.name:
                    return (await Promise.resolve().then(function () { return supplierProduct_entity; })).supplierProductFactory(this.injector);
            }
        }
        return null;
    }
    async list() {
        const m = RootConfig.module.name;
        return Promise.resolve(Object.values(RootConfig.entities).map((e) => ({ name: e.name, module: m })));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementEntityProvider, decorators: [{
            type: Injectable
        }] });

class AXMProcurementManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementModule, providers: [
            // Module Manifest Provider
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: ProcurementManagementManifest,
                multi: true,
            },
            // Provider references (now using tokens)
            {
                provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                useClass: AXMProcurementManagementPermissionDefinitionProvider,
                multi: true,
            },
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMProcurementManagementMenuProvider,
                multi: true,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMProcurementManagementEntityProvider,
                multi: true,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProcurementManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    providers: [
                        // Module Manifest Provider
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: ProcurementManagementManifest,
                            multi: true,
                        },
                        // Provider references (now using tokens)
                        {
                            provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                            useClass: AXMProcurementManagementPermissionDefinitionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMProcurementManagementMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMProcurementManagementEntityProvider,
                            multi: true,
                        },
                    ],
                }]
        }] });

//#region ----   Imports   ----
//#endregion
async function supplierProductFactory(injector) {
    const i18n = RootConfig.config.i18n + ':supplier-products.entities.supplier-product';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.supplierProduct.name,
        title: RootConfig.entities.supplierProduct.title,
        icon: RootConfig.entities.supplierProduct.icon,
        formats: {
            individual: RootConfig.entities.supplierProduct.title,
            plural: RootConfig.entities.supplierProduct.titlePlural,
            searchResult: {
                title: '{{ product.title }} - {{ supplier.displayName }}',
                description: RootConfig.module.title,
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'notes' },
            { name: 'archive' },
        ],
        groups: [
            {
                id: 'supplier-product-info',
                title: `@${i18n}.groups.supplier-product-info`,
            },
            {
                id: 'pricing-terms',
                title: `@${i18n}.groups.pricing-terms`,
            },
            {
                id: 'validity',
                title: '@general:terms.validation.validity',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'supplier-product-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'supplierId',
                title: `@${i18n}.fields.supplier.title`,
                groupId: 'supplier-product-info',
                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',
                            expose: [
                                { source: 'id', target: 'supplier.id' },
                                { source: 'person.displayName', target: 'supplier.displayName' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'productId',
                title: `@${i18n}.fields.product.title`,
                groupId: 'supplier-product-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig$2.module.name}.${RootConfig$2.entities.product.name}`,
                            textField: 'title',
                            valueField: 'id',
                            expose: [
                                { source: 'id', target: 'product.id' },
                                { source: 'code', target: 'product.code' },
                                { source: 'title', target: 'product.title' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'unitPrice',
                title: `@${i18n}.fields.unit-price.title`,
                groupId: 'pricing-terms',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                },
            },
            {
                name: 'currencyId',
                title: `@${i18n}.fields.currency.title`,
                groupId: 'pricing-terms',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig$3.module.name}.${RootConfig$3.entities.currency.name}`,
                            textField: 'code',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'currency.id' },
                                { source: 'code', target: 'currency.code' },
                                { source: 'symbol', target: 'currency.symbol' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'paymentTermsId',
                title: `@${i18n}.fields.payment-terms.title`,
                groupId: 'pricing-terms',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig$3.module.name}.${RootConfig$3.entities.paymentTerm.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'paymentTerms.id' },
                                { source: 'title', target: 'paymentTerms.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'minimumOrderQuantity',
                title: `@${i18n}.fields.minimum-order-quantity.title`,
                groupId: 'pricing-terms',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                },
            },
            {
                name: 'leadTimeDays',
                title: `@${i18n}.fields.lead-time-days.title`,
                groupId: 'pricing-terms',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                },
            },
            {
                name: 'priority',
                title: `@${i18n}.fields.priority.title`,
                groupId: 'supplier-product-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                },
            },
            {
                name: 'validFrom',
                title: '@general:terms.validation.valid-from',
                groupId: 'validity',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                },
            },
            {
                name: 'validTo',
                title: '@general:terms.validation.valid-to',
                groupId: 'validity',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                },
            },
        ],
        columns: [
            { name: 'supplierId', options: { dataPath: 'supplier.displayName' } },
            { name: 'productId', options: { dataPath: 'product.title' } },
            { name: 'unitPrice' },
            { name: 'currencyId', options: { dataPath: 'currency.code' } },
            { name: 'priority' },
            { name: 'leadTimeDays' },
            { name: 'validFrom' },
            { name: 'validTo' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'supplier-product-info' },
                        { id: 'pricing-terms' },
                        { id: 'validity' },
                    ],
                    properties: [
                        //{ name: 'supplierId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'productId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'priority', layout: { positions: { lg: { colSpan: 3, order: 3 } } } },
                        { name: 'unitPrice', layout: { positions: { lg: { colSpan: 4, order: 4 } } } },
                        { name: 'currencyId', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'paymentTermsId', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'minimumOrderQuantity', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'leadTimeDays', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        { name: 'validFrom', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                        { name: 'validTo', layout: { positions: { lg: { colSpan: 6, order: 10 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'supplier-product-info' },
                        { id: 'pricing-terms' },
                        { id: 'validity' },
                    ],
                    properties: [
                        //{ name: 'supplierId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'productId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'priority', layout: { positions: { lg: { colSpan: 3, order: 3 } } } },
                        { name: 'unitPrice', layout: { positions: { lg: { colSpan: 4, order: 4 } } } },
                        { name: 'currencyId', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'paymentTermsId', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'minimumOrderQuantity', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'leadTimeDays', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        { name: 'validFrom', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                        { name: 'validTo', layout: { positions: { lg: { colSpan: 6, order: 10 } } } },
                    ],
                },
                single: {
                    title: '{{ product.title }} - {{ supplier.displayName }}',
                    sections: [
                        { id: 'supplier-product-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'pricing-terms', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'validity', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'supplierId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'productId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'priority', layout: { positions: { lg: { colSpan: 3, order: 3 } } } },
                        { name: 'unitPrice', layout: { positions: { lg: { colSpan: 4, order: 4 } } } },
                        { name: 'currencyId', layout: { positions: { lg: { colSpan: 4, order: 5 } } } },
                        { name: 'paymentTermsId', layout: { positions: { lg: { colSpan: 4, order: 6 } } } },
                        { name: 'minimumOrderQuantity', layout: { positions: { lg: { colSpan: 6, order: 7 } } } },
                        { name: 'leadTimeDays', layout: { positions: { lg: { colSpan: 6, order: 8 } } } },
                        { name: 'validFrom', layout: { positions: { lg: { colSpan: 6, order: 9 } } } },
                        { name: 'validTo', layout: { positions: { lg: { colSpan: 6, order: 10 } } } },
                    ],
                    actions: [entityMasterDeleteAction()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'priority', dir: 'asc' }, { name: 'product.title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

var supplierProduct_entity = /*#__PURE__*/Object.freeze({
    __proto__: null,
    supplierProductFactory: supplierProductFactory
});

/**
 * Generated bundle index. Do not edit.
 */

export { AXMProcurementManagementModule, RootConfig, supplierProductFactory };
//# sourceMappingURL=acorex-modules-procurement-management.mjs.map
