import { AXP_MODULE_MANIFEST_PROVIDER, AXP_FEATURE_DEFINITION_PROVIDER } from '@acorex/platform/core';
import { AXPEntityService, entityMasterRecordActions, entityMasterCrudActions, AXMEntityCrudServiceImpl, entityDetailsCrudActions, AXP_ENTITY_DEFINITION_LOADER } from '@acorex/platform/layout/entity';
import { AXPStatusProvider, AXPSystemStatusType, systemStatusToDefinition, AXPSearchCommandProvider, createAllQueryView, AXP_STATUS_PROVIDERS, AXP_MENU_PROVIDER, AXP_SEARCH_PROVIDER } from '@acorex/platform/common';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { AXP_IDENTIFIER_RULES } from '@acorex/modules/identifier-management';
import * as i0 from '@angular/core';
import { Injectable, inject, Injector, NgModule } from '@angular/core';
import { AXTranslationService } from '@acorex/core/translation';
import { AXPCommonMenuKeys, AXPWidgetsList } from '@acorex/modules/common';

const config = {
    i18n: 'subscription-management',
    module: 'SubscriptionManagement',
};
const RootConfig = {
    config,
    module: {
        route: 'subscription-management',
        name: config.module,
        title: `@${config.i18n}:module.title`,
        icon: 'fa-light fa-credit-card',
    },
    entities: {
        subscription: {
            name: 'Subscription',
            source: `${config.module}.Subscription`,
            title: `@${config.i18n}:subscriptions.entities.subscription.title`,
            titlePlural: `@${config.i18n}:subscriptions.entities.subscription.plural`,
            icon: 'fa-light fa-credit-card',
        },
        subscriptionPlan: {
            name: 'SubscriptionPlan',
            source: `${config.module}.SubscriptionPlan`,
            title: `@${config.i18n}:subscriptions.entities.subscription-plan.title`,
            titlePlural: `@${config.i18n}:subscriptions.entities.subscription-plan.plural`,
            icon: 'fa-light fa-box',
        },
        subscriptionPlanItem: {
            name: 'SubscriptionPlanItem',
            source: `${config.module}.SubscriptionPlanItem`,
            title: `@${config.i18n}:subscriptions.entities.subscription-plan-item.title`,
            titlePlural: `@${config.i18n}:subscriptions.entities.subscription-plan-item.plural`,
            icon: 'fa-light fa-list-ul',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Subscription Management Module Manifest.
 * Defines module metadata, features, and provider references.
 */
const SubscriptionManagementManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
    required: true,
    // Module dependencies (optional)
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Status Provider   ----
/**
 * Subscription status provider defining lifecycle states: Active, Expired, Cancelled, Suspended.
 * Used by the status plugin to manage subscription status transitions and metadata.
 */
class AXMSubscriptionStatusProvider extends AXPStatusProvider {
    constructor() {
        super(...arguments);
        this.key = 'subscription-management.status.subscription';
        this.defaultStatus = AXPSystemStatusType.Active;
        this.statuses = [
            systemStatusToDefinition(AXPSystemStatusType.Active, {
                title: '@subscription-management:subscriptions.states.active',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Expired, {
                title: '@subscription-management:subscriptions.states.expired',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Cancelled, {
                title: '@subscription-management:subscriptions.states.cancelled',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Suspended, {
                title: '@subscription-management:subscriptions.states.suspended',
                generateView: true,
            }),
        ];
        this.transitions = [
            {
                from: AXPSystemStatusType.Active,
                to: AXPSystemStatusType.Expired,
                title: '@subscription-management:subscriptions.transitions.expire',
            },
            {
                from: AXPSystemStatusType.Active,
                to: AXPSystemStatusType.Cancelled,
                title: '@subscription-management:subscriptions.transitions.cancel',
            },
            {
                from: AXPSystemStatusType.Active,
                to: AXPSystemStatusType.Suspended,
                title: '@subscription-management:subscriptions.transitions.suspend',
            },
            {
                from: AXPSystemStatusType.Suspended,
                to: AXPSystemStatusType.Active,
                title: '@subscription-management:subscriptions.transitions.activate',
            },
            {
                from: AXPSystemStatusType.Expired,
                to: AXPSystemStatusType.Active,
                title: '@subscription-management:subscriptions.transitions.renew',
            },
        ];
    }
}
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Identifier Rules   ----
/**
 * Identifier rule for subscriptions
 * Format: SUB-{YYYYMM}-{####}
 * Example: SUB-202412-0001
 */
const AXM_SUBSCRIPTION_ID_IDENTIFIER_RULE = {
    id: 'subscription-management.subscription-id',
    title: 'Subscription ID',
    entity: 'SubscriptionManagement.Subscription',
    pattern: 'SUB-{date:YYYYMM}-{seq:4}',
    enabled: true,
    priority: 1,
    scopeConfig: { byTenant: false, period: 'monthly', minValue: 1, blockSize: 0 },
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Feature Definition Provider   ----
/**
 * Subscription Management Feature Definition Provider.
 * Provides feature definitions for the Subscription Management module.
 */
class AXMSubscriptionManagementFeatureDefinitionProvider {
    async provide(context) {
        // Management feature removed - module name is used directly as feature key
    }
}
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Keys   ----
const moduleKey = RootConfig.module.name;
const AXMPermissionsKeys = {
    SubscriptionManagement: {
        Management: `${moduleKey}:Permission:Management`,
        Subscriptions: {
            Management: `${moduleKey}:Permission:Subscriptions.Management`,
        },
        SubscriptionPlans: {
            Management: `${moduleKey}:Permission:SubscriptionPlans.Management`,
        },
    },
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Definition Provider   ----
class AXMSubscriptionManagementPermissionProvider {
    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 keys = AXMPermissionsKeys.SubscriptionManagement;
        const subscriptionsTrans = (action) => this.translateService.translateAsync(`@${RootConfig.config.i18n}:subscriptions.permissions.subscriptions.${action}.title`);
        const subscriptionPlansTrans = (action) => this.translateService.translateAsync(`@${RootConfig.config.i18n}:subscriptions.permissions.subscription-plans.${action}.title`);
        context
            .addGroup(RootConfig.module.name, await trans('module.title'))
            .addPermission(keys.Subscriptions.Management, await subscriptionsTrans('manage'))
            .endPermission()
            .addPermission(keys.SubscriptionPlans.Management, await subscriptionPlansTrans('manage'))
            .endPermission()
            .endGroup();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementPermissionProvider, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementPermissionProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementPermissionProvider, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i0.Injector }] });

const AXMSubscriptionManagementMenuKeys = {
    Root: 'SubscriptionManagement:Menu',
    Subscriptions: 'SubscriptionManagement:Menu:Subscriptions',
    SubscriptionPlans: 'SubscriptionManagement:Menu:SubscriptionPlans',
};

//#region ----   Imports   ----
//#endregion
//#region ----   Menu Provider   ----
class AXMSubscriptionManagementMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        context.find(AXPCommonMenuKeys.Platform).addItems([
            {
                name: AXMSubscriptionManagementMenuKeys.Subscriptions,
                text: `@${RootConfig.config.i18n}:subscriptions.entities.subscription.plural`,
                path: this.entityService.createPath(module.name, RootConfig.entities.subscription.name),
                icon: RootConfig.entities.subscription.icon,
                priority: 6,
                policy: {
                    features: [module.name],
                    permissions: [AXMPermissionsKeys.SubscriptionManagement.Subscriptions.Management],
                },
            },
            {
                name: AXMSubscriptionManagementMenuKeys.SubscriptionPlans,
                text: `@${RootConfig.config.i18n}:subscriptions.entities.subscription-plan.plural`,
                path: this.entityService.createPath(module.name, RootConfig.entities.subscriptionPlan.name),
                icon: RootConfig.entities.subscriptionPlan.icon,
                priority: 7,
                policy: {
                    features: [module.name],
                    permissions: [AXMPermissionsKeys.SubscriptionManagement.SubscriptionPlans.Management],
                },
            },
        ]);
    }
}
//#endregion

//#endregion
//#region ----   Entity Provider   ----
class AXMSubscriptionManagementEntityProvider {
    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.subscription.name:
                    return (await Promise.resolve().then(function () { return subscription_entity; })).subscriptionEntityFactory(this.injector);
                case RootConfig.entities.subscriptionPlan.name:
                    return (await Promise.resolve().then(function () { return subscriptionPlan_entity; })).subscriptionPlanEntityFactory(this.injector);
                case RootConfig.entities.subscriptionPlanItem.name:
                    return (await Promise.resolve().then(function () { return subscriptionPlanItem_entity; })).subscriptionPlanItemEntityFactory(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: AXMSubscriptionManagementEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementEntityProvider, decorators: [{
            type: Injectable
        }] });

//#region ----   Imports   ----
//#endregion
//#region ----   Search Command Provider   ----
class AXMSubscriptionManagementSearchProvider extends AXPSearchCommandProvider {
    constructor() {
        super(...arguments);
        this.commands = [
            {
                group: 'command',
                title: `@${RootConfig.config.i18n}:subscriptions.actions.create-subscription.title`,
                icon: RootConfig.entities.subscription.icon,
                description: `@${RootConfig.config.i18n}:subscriptions.actions.create-subscription.description`,
                command: {
                    name: 'create-entity',
                    options: {
                        entity: `${RootConfig.module.name}.${RootConfig.entities.subscription.name}`,
                    },
                },
            },
            {
                group: 'command',
                title: `@${RootConfig.config.i18n}:subscriptions.actions.create-subscription-plan.title`,
                icon: RootConfig.entities.subscriptionPlan.icon,
                description: `@${RootConfig.config.i18n}:subscriptions.actions.create-subscription-plan.description`,
                command: {
                    name: 'create-entity',
                    options: {
                        entity: `${RootConfig.module.name}.${RootConfig.entities.subscriptionPlan.name}`,
                    },
                },
            },
        ];
    }
}
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Entity Factory   ----
async function subscriptionEntityFactory(injector) {
    const i18n = RootConfig.config.i18n + ':subscriptions.entities.subscription';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.subscription.name,
        title: RootConfig.entities.subscription.title,
        icon: RootConfig.entities.subscription.icon,
        formats: {
            individual: RootConfig.entities.subscription.title,
            plural: RootConfig.entities.subscription.titlePlural,
            searchResult: {
                title: '{{ title }} - {{ subscriber.title }}',
                description: '{{ description }}',
            },
        },
        plugins: [
            {
                name: 'status',
                options: {
                    field: 'statusId',
                    definition: 'subscription-management.status.subscription',
                },
            },
            {
                name: 'identifier',
                options: {
                    field: 'id',
                    rule: 'subscription-management.subscription-id',
                },
            },
            { name: 'history' },
            { name: 'compare' },
            {
                name: 'notes',
            },
        ],
        groups: [
            {
                id: 'basic-info',
                title: `@${i18n}.groups.basic-info`,
            },
            {
                id: 'subscription-details',
                title: `@${i18n}.groups.subscription-details`,
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'planId',
                title: `@${i18n}.fields.plan.title`,
                groupId: 'subscription-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.subscriptionPlan.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'plan.id' },
                                { source: 'title', target: 'plan.title' },
                                { source: 'description', target: 'plan.description' },
                                { source: 'subscribableType', target: 'plan.subscribableType' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'subscriberId',
                title: `@${i18n}.fields.subscriber.title`,
                groupId: 'subscription-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            // Dynamic entity based on plan's subscribableType
                            // Will be resolved based on plan.subscribableType
                            entity: `TenantManagement.Tenant`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'subscriber.id' },
                                { source: 'title', target: 'subscriber.title' },
                                { source: 'title', target: 'subscriber.displayName' },
                            ],
                            // Filter will be applied based on plan's subscribableType
                            triggers: [
                                {
                                    event: "{{ events.context('planId') }}",
                                    action: `{{ widget.refresh() }}`,
                                },
                            ],
                        },
                    },
                },
                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: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: `@${i18n}.fields.title.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'description',
                title: `@${i18n}.fields.description.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                        },
                    },
                },
            },
            {
                name: 'startDate',
                title: `@${i18n}.fields.start-date.title`,
                groupId: 'subscription-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsList.Editors.DateTimeBox,
                        options: {
                            format: 'date',
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'endDate',
                title: `@${i18n}.fields.end-date.title`,
                groupId: 'subscription-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsList.Editors.DateTimeBox,
                        options: {
                            format: 'date',
                        },
                    },
                },
            },
        ],
        columns: [
            { name: 'title' },
            { name: 'planId', options: { dataPath: 'plan' } },
            { name: 'subscriberId', options: { dataPath: 'subscriber' } },
            { name: 'statusId' },
            { name: 'startDate' },
            { name: 'endDate' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'subscription-details',
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'planId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'subscriberId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'startDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'endDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'subscription-details',
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'planId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'subscriberId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'startDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'endDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'startDate', dir: 'desc' }],
                        }),
                    ],
                },
                single: {
                    title: '{{ title }} ',
                    description: '{{ description }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'subscription-details', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'planId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'subscriberId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Service   ----
class AXMSubscriptionManagementSubscriptionEntityService extends AXMEntityCrudServiceImpl {
}
class AXMSubscriptionManagementSubscriptionEntityServiceImpl extends AXMSubscriptionManagementSubscriptionEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.subscription.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

//#region ----   Subscription Model   ----
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Plan Entity Factory   ----
async function subscriptionPlanEntityFactory(injector) {
    const i18n = RootConfig.config.i18n + ':subscriptions.entities.subscription-plan';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.subscriptionPlan.name,
        title: RootConfig.entities.subscriptionPlan.title,
        icon: RootConfig.entities.subscriptionPlan.icon,
        formats: {
            individual: RootConfig.entities.subscriptionPlan.title,
            plural: RootConfig.entities.subscriptionPlan.titlePlural,
            displayName: RootConfig.entities.subscriptionPlan.title,
            searchResult: {
                title: '{{ title }}',
                description: '{{ description }}',
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'disable' },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.subscriptionPlanItem.name}`,
                title: RootConfig.entities.subscriptionPlanItem.titlePlural,
                icon: RootConfig.entities.subscriptionPlanItem.icon,
                conditions: [
                    {
                        name: 'planId', operator: { type: 'equal' },
                        value: '{{ context.eval("id") }}'
                    },
                ],
                actions: [...entityDetailsCrudActions('planId')],
                layout: { type: 'page-list', position: 'after', order: 1 },
            },
        ],
        groups: [
            {
                id: 'basic-info',
                title: `@${i18n}.groups.basic-info`,
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'code',
                title: `@${i18n}.fields.code.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: `@${i18n}.fields.code.placeholder`,
                        },
                    },
                },
            },
            {
                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: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: `@${i18n}.fields.title.placeholder`,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'description',
                title: `@${i18n}.fields.description.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: false },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                        },
                    },
                },
            },
        ],
        columns: [{ name: 'title' }, { name: 'code' }, { name: 'isDisabled' }],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        {
                            name: 'code',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'code', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Plan Service   ----
class AXMSubscriptionManagementSubscriptionPlanEntityService extends AXMEntityCrudServiceImpl {
}
class AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl extends AXMSubscriptionManagementSubscriptionPlanEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.subscriptionPlan.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

//#region ----   Subscription Plan Model   ----
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Plan Item Entity Factory   ----
async function subscriptionPlanItemEntityFactory(injector) {
    const i18n = RootConfig.config.i18n + ':subscriptions.entities.subscription-plan-item';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.subscriptionPlanItem.name,
        title: RootConfig.entities.subscriptionPlanItem.title,
        icon: RootConfig.entities.subscriptionPlanItem.icon,
        formats: {
            individual: RootConfig.entities.subscriptionPlanItem.title,
            plural: RootConfig.entities.subscriptionPlanItem.titlePlural,
            searchResult: {
                title: '{{ edition.title }}',
                description: '{{ plan.title }}',
            },
        },
        groups: [
            {
                id: 'basic-info',
                title: `@${i18n}.groups.basic-info`,
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'subscribableType',
                title: `@${i18n}.fields.subscribable-type.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    defaultValue: 'ApplicationEdition',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'value',
                            textField: 'text',
                            dataSource: [
                                { value: 'ApplicationEdition', text: '@subscription-management:subscriptions.terms.application-edition' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'planId',
                title: `@${i18n}.fields.plan.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.subscriptionPlan.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'plan.id' },
                                { source: 'title', target: 'plan.title' },
                                { source: 'description', target: 'plan.description' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'editionId',
                title: `@${i18n}.fields.edition.title`,
                groupId: 'basic-info',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `ApplicationManagement.Edition`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'edition.id' },
                                { source: 'title', target: 'edition.title' },
                                { source: 'description', target: 'edition.description' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
        ],
        columns: [
            { name: 'subscribableType' },
            //{ name: 'planId', options: { dataPath: 'plan.title' } },
            { name: 'editionId', options: { dataPath: 'edition.title' } },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        // {
                        //   name: 'planId',
                        //   layout: {
                        //     positions: {
                        //       lg: {
                        //         colSpan: 12,
                        //       },
                        //     },
                        //   },
                        // },
                        {
                            name: 'subscribableType',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'editionId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        // {
                        //   name: 'planId',
                        //   layout: {
                        //     positions: {
                        //       lg: {
                        //         colSpan: 12,
                        //       },
                        //     },
                        //   },
                        // },
                        {
                            name: 'subscribableType',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'editionId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'planId', dir: 'asc' }],
                        }),
                    ],
                },
                single: {
                    title: '{{ edition.title }} - {{ plan.title }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        //{ name: 'planId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'subscribableType', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'editionId', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Plan Item Service   ----
class AXMSubscriptionManagementSubscriptionPlanItemEntityService extends AXMEntityCrudServiceImpl {
}
class AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl extends AXMSubscriptionManagementSubscriptionPlanItemEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.subscriptionPlanItem.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

//#region ----   Subscription Plan Item Model   ----
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Subscription Management Module   ----
class AXMSubscriptionManagementModule {
    constructor() { }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementModule, providers: [
            // Module-specific providers (not part of manifest system)
            {
                provide: AXMSubscriptionManagementSubscriptionEntityService,
                useClass: AXMSubscriptionManagementSubscriptionEntityServiceImpl,
            },
            {
                provide: AXMSubscriptionManagementSubscriptionPlanEntityService,
                useClass: AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl,
            },
            {
                provide: AXMSubscriptionManagementSubscriptionPlanItemEntityService,
                useClass: AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl,
            },
            {
                provide: AXP_STATUS_PROVIDERS,
                useClass: AXMSubscriptionStatusProvider,
                multi: true,
            },
            {
                provide: AXP_IDENTIFIER_RULES,
                multi: true,
                useValue: AXM_SUBSCRIPTION_ID_IDENTIFIER_RULE,
            },
            // Module Manifest Provider
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: SubscriptionManagementManifest,
                multi: true,
            },
            // Provider references (now using tokens)
            {
                provide: AXP_FEATURE_DEFINITION_PROVIDER,
                useClass: AXMSubscriptionManagementFeatureDefinitionProvider,
                multi: true,
            },
            {
                provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                useClass: AXMSubscriptionManagementPermissionProvider,
                multi: true,
            },
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMSubscriptionManagementMenuProvider,
                multi: true,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMSubscriptionManagementEntityProvider,
                multi: true,
            },
            {
                provide: AXP_SEARCH_PROVIDER,
                useClass: AXMSubscriptionManagementSearchProvider,
                multi: true,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMSubscriptionManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    providers: [
                        // Module-specific providers (not part of manifest system)
                        {
                            provide: AXMSubscriptionManagementSubscriptionEntityService,
                            useClass: AXMSubscriptionManagementSubscriptionEntityServiceImpl,
                        },
                        {
                            provide: AXMSubscriptionManagementSubscriptionPlanEntityService,
                            useClass: AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl,
                        },
                        {
                            provide: AXMSubscriptionManagementSubscriptionPlanItemEntityService,
                            useClass: AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl,
                        },
                        {
                            provide: AXP_STATUS_PROVIDERS,
                            useClass: AXMSubscriptionStatusProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_IDENTIFIER_RULES,
                            multi: true,
                            useValue: AXM_SUBSCRIPTION_ID_IDENTIFIER_RULE,
                        },
                        // Module Manifest Provider
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: SubscriptionManagementManifest,
                            multi: true,
                        },
                        // Provider references (now using tokens)
                        {
                            provide: AXP_FEATURE_DEFINITION_PROVIDER,
                            useClass: AXMSubscriptionManagementFeatureDefinitionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                            useClass: AXMSubscriptionManagementPermissionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMSubscriptionManagementMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMSubscriptionManagementEntityProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_SEARCH_PROVIDER,
                            useClass: AXMSubscriptionManagementSearchProvider,
                            multi: true,
                        },
                    ],
                }]
        }], ctorParameters: () => [] });

// Management feature removed - module name is used directly as feature key
const AXMSubscriptionManagementFeatureKeys = {};

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

export { AXMPermissionsKeys, AXMSubscriptionManagementEntityProvider, AXMSubscriptionManagementFeatureDefinitionProvider, AXMSubscriptionManagementFeatureKeys, AXMSubscriptionManagementMenuKeys, AXMSubscriptionManagementMenuProvider, AXMSubscriptionManagementModule, AXMSubscriptionManagementSearchProvider, AXMSubscriptionManagementSubscriptionEntityService, AXMSubscriptionManagementSubscriptionEntityServiceImpl, AXMSubscriptionManagementSubscriptionPlanEntityService, AXMSubscriptionManagementSubscriptionPlanEntityServiceImpl, AXMSubscriptionManagementSubscriptionPlanItemEntityService, AXMSubscriptionManagementSubscriptionPlanItemEntityServiceImpl, RootConfig, subscriptionEntityFactory, subscriptionPlanEntityFactory, subscriptionPlanItemEntityFactory };
//# sourceMappingURL=acorex-modules-subscription-management.mjs.map
