import * as i0 from '@angular/core';
import { Injectable, inject, Injector, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AXP_MODULE_MANIFEST_PROVIDER, AXP_FEATURE_DEFINITION_PROVIDER } from '@acorex/platform/core';
import { AXPEntityService, AXP_ENTITY_DEFINITION_LOADER } from '@acorex/platform/layout/entity';
import { AXPStatusProvider, AXPSystemStatusType, systemStatusToDefinition, AXP_STATUS_PROVIDERS, AXP_MENU_PROVIDER, AXP_SEARCH_PROVIDER } from '@acorex/platform/common';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { AXTranslationService } from '@acorex/core/translation';
import { AXMBusinessCoreMenuKeys } from '@acorex/modules/business-core';
import { AXPCommonMenuKeys } from '@acorex/modules/common';

const config = {
    i18n: 'product-catalog',
    module: 'ProductCatalog',
};
const RootConfig = {
    config,
    module: {
        route: 'product-catalog',
        name: config.module,
        title: '@product-catalog:module.title',
        icon: 'fa-light fa-box-open',
    },
    entities: {
        brand: {
            name: 'Brand',
            source: `${config.module}.Brand`,
            title: '@product-catalog:brands.entities.brand.title',
            titlePlural: '@product-catalog:brands.entities.brand.plural',
            icon: 'fa-light fa-copyright',
        },
        productCategory: {
            name: 'ProductCategory',
            source: `${config.module}.ProductCategory`,
            title: '@product-catalog:categories.entities.product-category.title',
            titlePlural: '@product-catalog:categories.entities.product-category.plural',
            icon: 'fa-light fa-folder-tree',
        },
        product: {
            name: 'Product',
            source: `${config.module}.Product`,
            title: '@product-catalog:products.entities.product.title',
            titlePlural: '@product-catalog:products.entities.product.plural',
            icon: 'fa-light fa-box',
        },
        productSku: {
            name: 'ProductSku',
            source: `${config.module}.ProductSku`,
            title: '@product-catalog:skus.entities.product-sku.title',
            titlePlural: '@product-catalog:skus.entities.product-sku.plural',
            icon: 'fa-light fa-barcode',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Product Catalog Module Manifest.
 * Defines module metadata, features, and provider references.
 */
const ProductCatalogManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
    // Module dependencies
    dependencies: [
        'MeasurementCore',
        'FinancialCore',
        'BusinessCore',
        'SupplierManagement',
        'ProcurementManagement',
        'DataManagement',
        'DataManagement.MetaDataDefinitions',
    ],
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Product Status Provider   ----
/**
 * Product status provider defining lifecycle states: Draft, Review, Approved, Suspended, Discontinued.
 * Used by the status plugin to manage product status transitions and metadata.
 */
class AXMProductStatusProvider extends AXPStatusProvider {
    constructor() {
        super(...arguments);
        this.key = 'product-catalog.status.product';
        this.defaultStatus = AXPSystemStatusType.Draft;
        this.statuses = [
            systemStatusToDefinition(AXPSystemStatusType.Draft, {
                title: '@product-catalog:products.states.draft',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.InReview, {
                title: '@product-catalog:products.states.in-review',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Approved, {
                title: '@product-catalog:products.states.approved',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Suspended, {
                title: '@product-catalog:products.states.suspended',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Archived, {
                title: '@product-catalog:products.states.archived',
                generateView: true,
            }),
        ];
        this.transitions = [
            {
                from: AXPSystemStatusType.Draft,
                to: AXPSystemStatusType.InReview,
                title: '@general:statuses.transitions.submit',
            },
            {
                from: AXPSystemStatusType.InReview,
                to: AXPSystemStatusType.Approved,
                title: '@general:statuses.transitions.approve',
            },
            {
                from: AXPSystemStatusType.InReview,
                to: AXPSystemStatusType.Draft,
                title: '@general:statuses.transitions.reject',
            },
            {
                from: AXPSystemStatusType.Approved,
                to: AXPSystemStatusType.Suspended,
                title: '@general:statuses.transitions.suspend',
            },
            {
                from: AXPSystemStatusType.Suspended,
                to: AXPSystemStatusType.Approved,
                title: '@general:statuses.transitions.activate',
            },
            {
                from: AXPSystemStatusType.Approved,
                to: AXPSystemStatusType.Archived,
                title: '@general:statuses.transitions.archive',
            },
            {
                from: AXPSystemStatusType.Suspended,
                to: AXPSystemStatusType.Archived,
                title: '@general:statuses.transitions.archive',
            },
        ];
    }
}
//#endregion

//#region ----   Permission Keys   ----
const AXPProductCatalogPermissionKeys = {
    Products: {
        Management: 'ProductCatalog:Permission:Products.Management',
        View: 'ProductCatalog:Permission:Products.View',
        Create: 'ProductCatalog:Permission:Products.Create',
        Edit: 'ProductCatalog:Permission:Products.Edit',
        Delete: 'ProductCatalog:Permission:Products.Delete',
    },
    Brands: {
        Management: 'ProductCatalog:Permission:Brands.Management',
        View: 'ProductCatalog:Permission:Brands.View',
        Create: 'ProductCatalog:Permission:Brands.Create',
        Edit: 'ProductCatalog:Permission:Brands.Edit',
        Delete: 'ProductCatalog:Permission:Brands.Delete',
    },
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Definition Provider   ----
class AXPProductCatalogPermissionDefinitionProvider {
    constructor(injector) {
        this.injector = injector;
        this.translateService = this.injector.get(AXTranslationService);
    }
    async define(context) {
        const trans = async (key) => await this.translateService.translateAsync(key);
        const keys = AXPProductCatalogPermissionKeys;
        context
            .addGroup(RootConfig.module.name, await trans('@product-catalog:module.title'))
            // Products Management
            .addPermission(keys.Products.Management, await trans('@product-catalog:permissions.products.title'))
            .addChild(keys.Products.View, await trans('@product-catalog:permissions.products.actions.view.title'))
            .addChild(keys.Products.Edit, await trans('@general:actions.edit.title'))
            .addChild(keys.Products.Delete, await trans('@general:actions.delete.title'))
            .addChild(keys.Products.Create, await trans('@general:actions.create.title'))
            .endPermission()
            // Brands Management
            .addPermission(keys.Brands.Management, await trans('@product-catalog:permissions.brands.title'))
            .addChild(keys.Brands.View, await trans('@product-catalog:permissions.brands.actions.view.title'))
            .addChild(keys.Brands.Edit, await trans('@general:actions.edit.title'))
            .addChild(keys.Brands.Delete, await trans('@general:actions.delete.title'))
            .addChild(keys.Brands.Create, await trans('@general:actions.create.title'))
            .endPermission()
            //
            .endGroup();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXPProductCatalogPermissionDefinitionProvider, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXPProductCatalogPermissionDefinitionProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXPProductCatalogPermissionDefinitionProvider, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i0.Injector }] });

const AXPProductCatalogMenuKeys = {
    Root: 'ProductCatalog:Menu',
    Products: 'ProductCatalog:Menu:Products',
    Brands: 'ProductCatalog:Menu:Brands',
    Divider1: 'ProductCatalog:Menu:Divider1',
};

class AXMProductCatalogMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        // Commerce: Products
        context.find(AXPCommonMenuKeys.Commerce).addItems([
            {
                name: AXPProductCatalogMenuKeys.Products,
                text: '@product-catalog:products.menus.products.title',
                path: this.entityService.createPath(module.name, RootConfig.entities.product.name),
                icon: RootConfig.entities.product.icon,
                priority: 1,
                policy: {
                    features: [module.name],
                },
            },
            { name: AXPProductCatalogMenuKeys.Divider1, text: '', type: 'break', priority: 2 },
        ]);
        // Configuration/Business: Brands
        context.find(AXMBusinessCoreMenuKeys.Root).addItems([
            { name: `${AXPProductCatalogMenuKeys.Root}:brands-divider`, text: '', type: 'break', priority: 10 },
            {
                name: AXPProductCatalogMenuKeys.Brands,
                text: '@product-catalog:brands.menus.brands.title',
                path: this.entityService.createPath(module.name, RootConfig.entities.brand.name),
                icon: RootConfig.entities.brand.icon,
                priority: 11,
                policy: {
                    features: [module.name],
                },
            },
        ]);
    }
}

class AXMProductCatalogEntityProvider {
    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.brand.name:
                    return (await import('./acorex-modules-product-catalog-brand.entity-C8VOfwF0.mjs')).brandFactory(this.injector);
                case RootConfig.entities.product.name:
                    return (await import('./acorex-modules-product-catalog-product.entity-CVW7-ye7.mjs')).productFactory(this.injector);
                case RootConfig.entities.productSku.name:
                    return (await import('./acorex-modules-product-catalog-product-sku.entity-BNJHLs-b.mjs')).productSkuFactory(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: AXMProductCatalogEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogEntityProvider, decorators: [{
            type: Injectable
        }] });

//#region ----   Imports   ----
//#endregion
//#region ----   Feature Definition Provider   ----
/**
 * Product Catalog Feature Definition Provider.
 * Provides feature definitions for the Product Catalog module.
 */
class AXPProductCatalogFeatureDefinitionProvider {
    async provide(context) {
    }
}
//#endregion

class AXMProductCatalogSearchCommandProvider {
    async search(text) {
        // Entity search is handled by the entity search system
        // This provider is only needed if custom search logic is required
        return [];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogSearchCommandProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogSearchCommandProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogSearchCommandProvider, decorators: [{
            type: Injectable
        }] });

class AXMProductCatalogModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogModule, imports: [CommonModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogModule, providers: [
            // Module-specific providers (not part of manifest system)
            {
                provide: AXP_STATUS_PROVIDERS,
                useClass: AXMProductStatusProvider,
                multi: true,
            },
            // Module Manifest Provider
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: ProductCatalogManifest,
                multi: true,
            },
            // Provider references (now using tokens)
            {
                provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                useClass: AXPProductCatalogPermissionDefinitionProvider,
                multi: true,
            },
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMProductCatalogMenuProvider,
                multi: true,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMProductCatalogEntityProvider,
                multi: true,
            },
            {
                provide: AXP_FEATURE_DEFINITION_PROVIDER,
                useClass: AXPProductCatalogFeatureDefinitionProvider,
                multi: true,
            },
            {
                provide: AXP_SEARCH_PROVIDER,
                useClass: AXMProductCatalogSearchCommandProvider,
                multi: true,
            },
        ], imports: [CommonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMProductCatalogModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CommonModule,
                    ],
                    providers: [
                        // Module-specific providers (not part of manifest system)
                        {
                            provide: AXP_STATUS_PROVIDERS,
                            useClass: AXMProductStatusProvider,
                            multi: true,
                        },
                        // Module Manifest Provider
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: ProductCatalogManifest,
                            multi: true,
                        },
                        // Provider references (now using tokens)
                        {
                            provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                            useClass: AXPProductCatalogPermissionDefinitionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMProductCatalogMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMProductCatalogEntityProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_FEATURE_DEFINITION_PROVIDER,
                            useClass: AXPProductCatalogFeatureDefinitionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_SEARCH_PROVIDER,
                            useClass: AXMProductCatalogSearchCommandProvider,
                            multi: true,
                        },
                    ],
                }]
        }] });

// Entity Types

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

export { AXMProductCatalogEntityProvider, AXMProductCatalogMenuProvider, AXMProductCatalogModule, AXMProductCatalogSearchCommandProvider, AXMProductStatusProvider, AXPProductCatalogMenuKeys, AXPProductCatalogPermissionDefinitionProvider, AXPProductCatalogPermissionKeys, RootConfig };
//# sourceMappingURL=acorex-modules-product-catalog.mjs.map
