import { AXP_ENTITY_STORAGE_BACKEND, AXPMiddlewareAbortError, AXPEntityService, AXMEntityCrudServiceImpl, AXP_ENTITY_STORAGE_MIDDLEWARE, AXP_ENTITY_DEFINITION_LOADER, entityMasterCrudActions, entityMasterRecordActions, entityDetailsCrudActions } from '@acorex/platform/layout/entity';
import { AXP_MODULE_MANIFEST_PROVIDER, AXP_FEATURE_DEFINITION_PROVIDER, AXPSystemActionType } from '@acorex/platform/core';
import { AXPStatusProvider, AXPSystemStatusType, systemStatusToDefinition, AXPSearchCommandProvider, AXP_STATUS_PROVIDERS, AXP_MENU_PROVIDER, AXP_SETTING_DEFINITION_PROVIDER, AXP_SEARCH_PROVIDER, createAllQueryView, AXPEntityCommandScope } from '@acorex/platform/common';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import * as i0 from '@angular/core';
import { inject, Injectable, Injector, NgModule } from '@angular/core';
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$2 } from '@acorex/modules/location-management';
import { RootConfig as RootConfig$3 } from '@acorex/modules/locale-management';
import { RootConfig as RootConfig$1 } from '@acorex/modules/subscription-management';
import { RootConfig as RootConfig$4 } from '@acorex/modules/security-management';

const config = {
    i18n: 'tenant-management',
    module: 'TenantManagement',
};
const RootConfig = {
    config,
    module: {
        route: 'tenant-management',
        name: config.module,
        title: `@${config.i18n}:module.title`,
        icon: 'fa-light fa-building',
    },
    entities: {
        tenant: {
            name: 'Tenant',
            source: `${config.module}.Tenant`,
            title: `@${config.i18n}:tenants.entities.tenant.title`,
            titlePlural: `@${config.i18n}:tenants.entities.tenant.plural`,
            icon: 'fa-light fa-building',
        },
        tenantUser: {
            name: 'TenantUser',
            source: `${config.module}.TenantUser`,
            title: `@${config.i18n}:tenants.entities.tenant-user.title`,
            titlePlural: `@${config.i18n}:tenants.entities.tenant-user.plural`,
            icon: 'fa-light fa-user-group',
        },
    },
};
// Keep the old export for backward compatibility
const AXMTenantManagementModuleConst = {
    moduleName: 'TenantManagement',
    moduleRoute: 'tenant-management',
    i18n: 'tenant-management',
};

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Tenant Management Module Manifest.
 * Defines module metadata, features, and provider references.
 */
const TenantManagementManifest = {
    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 ----   Tenant Status Provider   ----
/**
 * Tenant status provider defining lifecycle states for tenants.
 * Used by the status plugin to manage tenant status transitions and metadata.
 */
class AXMTenantStatusProvider extends AXPStatusProvider {
    constructor() {
        super(...arguments);
        this.key = 'tenant-management.status.tenant';
        this.defaultStatus = AXPSystemStatusType.Active;
        this.statuses = [
            systemStatusToDefinition(AXPSystemStatusType.Active, {
                title: '@tenant-management:tenants.states.active',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Inactive, {
                title: '@tenant-management:tenants.states.inactive',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Suspended, {
                title: '@tenant-management:tenants.states.suspended',
                generateView: true,
            }),
            systemStatusToDefinition(AXPSystemStatusType.Pending, {
                title: '@tenant-management:tenants.states.pending',
                generateView: true,
            }),
        ];
        this.transitions = [
            {
                from: AXPSystemStatusType.Pending,
                to: AXPSystemStatusType.Active,
                title: '@tenant-management:tenants.transitions.activate',
            },
            {
                from: AXPSystemStatusType.Active,
                to: AXPSystemStatusType.Inactive,
                title: '@tenant-management:tenants.transitions.deactivate',
            },
            {
                from: AXPSystemStatusType.Active,
                to: AXPSystemStatusType.Suspended,
                title: '@tenant-management:tenants.transitions.suspend',
            },
            {
                from: AXPSystemStatusType.Suspended,
                to: AXPSystemStatusType.Active,
                title: '@tenant-management:tenants.transitions.resume',
            },
            {
                from: AXPSystemStatusType.Inactive,
                to: AXPSystemStatusType.Active,
                title: '@tenant-management:tenants.transitions.activate',
            },
        ];
    }
}
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Tenant User Account Holder Middleware   ----
/**
 * Tenant User Account Holder Enforcement Middleware
 *
 * Enforces business rules for the isAccountHolder flag:
 * 1. CREATE: Prevents manual creation with isAccountHolder=true (must use TransferOwnership command)
 * 2. UPDATE:
 *    - Prevents deactivating account holder
 *    - Prevents manually toggling isAccountHolder flag
 * 3. DELETE: Prevents deleting account holder
 *
 * Runs on: TenantUser entity operations
 */
const tenantUserAccountHolderMiddleware = {
    target: {
        ops: ['create', 'update', 'delete'],
        order: 10, // Early enforcement before other business logic
    },
    execute: async (ctx, next) => {
        const entityFullName = `${RootConfig.module.name}.${RootConfig.entities.tenantUser.name}`;
        // Only apply to TenantUser entity
        if (ctx.entityName !== entityFullName) {
            await next();
            return;
        }
        const backend = inject(AXP_ENTITY_STORAGE_BACKEND);
        //#region ----   CREATE Operation   ----
        if (ctx.op === 'create') {
            // Rule 1: Cannot manually create account holder
            // Must use TransferOwnership command instead
            if (ctx.data?.isAccountHolder === true) {
                throw new AXPMiddlewareAbortError('Cannot manually create tenant user as account holder. Use Transfer Ownership command.', {
                    status: 400,
                    code: 'TENANT_USER_ACCOUNT_HOLDER_MANUAL_CREATE',
                    details: {
                        entity: ctx.entityName,
                        field: 'isAccountHolder',
                    },
                });
            }
            // Ensure isAccountHolder is explicitly set to false for new users
            if (ctx.data) {
                ctx.data.isAccountHolder = false;
            }
        }
        //#endregion
        //#region ----   UPDATE Operation   ----
        if (ctx.op === 'update') {
            // Load existing record to check current state
            let existing;
            try {
                existing = await backend.getOne(ctx.entityName, ctx.id);
            }
            catch (error) {
                // If record doesn't exist, let it fail naturally in next()
                await next();
                return;
            }
            // Rule 2: Cannot manually toggle isAccountHolder flag
            if (ctx.data?.isAccountHolder !== undefined &&
                ctx.data.isAccountHolder !== existing.isAccountHolder) {
                throw new AXPMiddlewareAbortError('Cannot manually change account holder status. Use Transfer Ownership command.', {
                    status: 400,
                    code: 'TENANT_USER_ACCOUNT_HOLDER_MANUAL_TOGGLE',
                    details: {
                        entity: ctx.entityName,
                        id: ctx.id,
                        currentValue: existing.isAccountHolder,
                        attemptedValue: ctx.data.isAccountHolder,
                    },
                });
            }
            // Rule 3: Cannot deactivate account holder
            if (existing.isAccountHolder === true) {
                // Check if trying to deactivate (status change to inactive/disabled)
                if (ctx.data?.statusId && ctx.data.statusId !== 'active') {
                    throw new AXPMiddlewareAbortError('Cannot deactivate account holder. Transfer ownership to another user first.', {
                        status: 400,
                        code: 'TENANT_USER_ACCOUNT_HOLDER_DEACTIVATE',
                        details: {
                            entity: ctx.entityName,
                            id: ctx.id,
                            tenantId: existing.tenantId,
                            userId: existing.userId,
                        },
                    });
                }
                // Prevent end date before current date for account holder
                if (ctx.data?.endDate) {
                    const endDate = new Date(ctx.data.endDate);
                    const now = new Date();
                    if (endDate < now) {
                        throw new AXPMiddlewareAbortError('Cannot set past end date for account holder. Transfer ownership first.', {
                            status: 400,
                            code: 'TENANT_USER_ACCOUNT_HOLDER_END_DATE',
                            details: {
                                entity: ctx.entityName,
                                id: ctx.id,
                                endDate: ctx.data.endDate,
                            },
                        });
                    }
                }
            }
        }
        //#endregion
        //#region ----   DELETE Operation   ----
        if (ctx.op === 'delete') {
            // Load existing record to check if it's an account holder
            let existing;
            try {
                existing = await backend.getOne(ctx.entityName, ctx.id);
            }
            catch (error) {
                // If record doesn't exist, let it fail naturally in next()
                await next();
                return;
            }
            // Rule 4: Cannot delete account holder
            if (existing?.isAccountHolder === true) {
                throw new AXPMiddlewareAbortError('Cannot delete account holder. Transfer ownership to another user first.', {
                    status: 400,
                    code: 'TENANT_USER_ACCOUNT_HOLDER_DELETE',
                    details: {
                        entity: ctx.entityName,
                        id: ctx.id,
                        tenantId: existing.tenantId,
                        userId: existing.userId,
                    },
                });
            }
        }
        //#endregion
        // Execute the operation if all validations passed
        await next();
    },
};
//#endregion

//#region ----   Middleware Exports   ----
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Feature Definition Provider   ----
/**
 * Tenant Management Feature Definition Provider.
 * Provides feature definitions for the Tenant Management module.
 */
class AXMTenantManagementFeatureDefinitionProvider {
    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 AXMTenantManagementPermissionsKeys = {
    TenantManagement: {
        Management: `${moduleKey}:Permission:Management`,
    },
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Definition Provider   ----
class AXMTenantManagementPermissionDefinitionProvider {
    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}`);
        context
            .addGroup(RootConfig.module.name, await trans('module.title'))
            .addPermission(AXMTenantManagementPermissionsKeys.TenantManagement.Management, await trans('tenants.permissions.tenants.title'))
            .endPermission()
            .endGroup();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementPermissionDefinitionProvider, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementPermissionDefinitionProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementPermissionDefinitionProvider, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i0.Injector }] });

const AXMTenantManagementMenuKeys = {
    Root: 'TenantManagement:Menu',
    Tenants: 'TenantManagement:Menu:Tenants',
};

//#region ----   Imports   ----
//#endregion
//#region ----   Menu Provider   ----
class AXMTenantManagementModuleMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        context.find(AXPCommonMenuKeys.Platform).addItems([
            {
                name: AXMTenantManagementMenuKeys.Tenants,
                text: `@${RootConfig.config.i18n}:tenants.entities.tenant.plural`,
                path: this.entityService.createPath(module.name, RootConfig.entities.tenant.name),
                icon: RootConfig.entities.tenant.icon,
                priority: 4,
                policy: {
                    features: [module.name],
                    permissions: [AXMTenantManagementPermissionsKeys.TenantManagement.Management],
                },
            },
            { name: `${AXMTenantManagementMenuKeys.Root}:divider`, text: '', type: 'break', priority: 5 },
        ]);
    }
}
//#endregion

//#endregion
//#region ----   Entity Provider   ----
class AXMTenantManagementEntityProvider {
    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.tenant.name:
                    return (await Promise.resolve().then(function () { return tenant_entity; })).tenantEntityFactory(this.injector);
                case RootConfig.entities.tenantUser.name:
                    return (await Promise.resolve().then(function () { return tenantUser_entity; })).tenantUserEntityFactory(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: AXMTenantManagementEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementEntityProvider, decorators: [{
            type: Injectable
        }] });

class AXMTenantSettingProvider {
    constructor() {
        this.translationService = inject(AXTranslationService);
    }
    async provide(context) {
        const scope = RootConfig.config.i18n;
        const trans = async (key) => await this.translationService.translateAsync(`@${scope}:tenants.settings.tenant.${key}`);
        context
            .addGroup('tenant', await trans('group.title'), await trans('group.description'), RootConfig.module.icon)
            .addSection('general', await trans('sections.general.title'), await trans('sections.general.description'))
            // TODO: Add tenant-specific settings here when needed
            .endSection()
            .endGroup();
    }
}

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

class AXMTenantService extends AXMEntityCrudServiceImpl {
}
class AXMTenantServiceImpl extends AXMTenantService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.tenant.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

class AXMTenantEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantEntityModule, providers: [
            {
                provide: AXMTenantService,
                useClass: AXMTenantServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [],
                    imports: [],
                    exports: [],
                    providers: [
                        {
                            provide: AXMTenantService,
                            useClass: AXMTenantServiceImpl,
                        },
                    ],
                }]
        }] });

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

//#region ----   Imports   ----
//#endregion
//#region ----   Tenant User Module   ----
class AXMTenantUserEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantUserEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantUserEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantUserEntityModule, providers: [
            {
                provide: AXMTenantManagementTenantUserEntityService,
                useClass: AXMTenantManagementTenantUserEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantUserEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXMTenantManagementTenantUserEntityService,
                            useClass: AXMTenantManagementTenantUserEntityServiceImpl,
                        },
                    ],
                }]
        }] });

class AXMTenantManagementModule {
    constructor() { }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementModule, imports: [
            // Entity Modules
            AXMTenantEntityModule,
            AXMTenantUserEntityModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementModule, providers: [
            // Module-specific providers (not part of manifest system)
            {
                provide: AXP_STATUS_PROVIDERS,
                useClass: AXMTenantStatusProvider,
                multi: true,
            },
            {
                provide: AXP_ENTITY_STORAGE_MIDDLEWARE,
                useValue: tenantUserAccountHolderMiddleware,
                multi: true,
            },
            // Module Manifest Provider
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: TenantManagementManifest,
                multi: true,
            },
            // Provider references (now using tokens)
            {
                provide: AXP_FEATURE_DEFINITION_PROVIDER,
                useClass: AXMTenantManagementFeatureDefinitionProvider,
                multi: true,
            },
            {
                provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                useClass: AXMTenantManagementPermissionDefinitionProvider,
                multi: true,
            },
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMTenantManagementModuleMenuProvider,
                multi: true,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMTenantManagementEntityProvider,
                multi: true,
            },
            {
                provide: AXP_SETTING_DEFINITION_PROVIDER,
                useClass: AXMTenantSettingProvider,
                multi: true,
            },
            {
                provide: AXP_SEARCH_PROVIDER,
                useClass: AXMTenantSearchCommandProvider,
                multi: true,
            },
        ], imports: [
            // Entity Modules
            AXMTenantEntityModule,
            AXMTenantUserEntityModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMTenantManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        // Entity Modules
                        AXMTenantEntityModule,
                        AXMTenantUserEntityModule,
                    ],
                    exports: [],
                    declarations: [],
                    providers: [
                        // Module-specific providers (not part of manifest system)
                        {
                            provide: AXP_STATUS_PROVIDERS,
                            useClass: AXMTenantStatusProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_STORAGE_MIDDLEWARE,
                            useValue: tenantUserAccountHolderMiddleware,
                            multi: true,
                        },
                        // Module Manifest Provider
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: TenantManagementManifest,
                            multi: true,
                        },
                        // Provider references (now using tokens)
                        {
                            provide: AXP_FEATURE_DEFINITION_PROVIDER,
                            useClass: AXMTenantManagementFeatureDefinitionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_PERMISSION_DEFINITION_PROVIDER,
                            useClass: AXMTenantManagementPermissionDefinitionProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMTenantManagementModuleMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMTenantManagementEntityProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_SETTING_DEFINITION_PROVIDER,
                            useClass: AXMTenantSettingProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_SEARCH_PROVIDER,
                            useClass: AXMTenantSearchCommandProvider,
                            multi: true,
                        },
                    ],
                }]
        }], ctorParameters: () => [] });

//#region ----   Imports   ----
//#endregion
//#region ----   Tenant Entity Factory   ----
async function tenantEntityFactory(injector) {
    const i18n = RootConfig.config.i18n + ':tenants.entities.tenant';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.tenant.name,
        icon: RootConfig.entities.tenant.icon,
        title: RootConfig.entities.tenant.title,
        plugins: [
            {
                name: 'status',
                options: {
                    field: 'statusId',
                    definition: 'tenant-management.status.tenant',
                },
            },
            {
                name: 'avatar',
                options: {
                    group: 'branding',
                },
            },
            {
                name: 'color',
                options: {
                    group: 'branding',
                },
            },
            {
                name: 'notes',
            },
        ],
        formats: {
            individual: RootConfig.entities.tenant.title,
            plural: RootConfig.entities.tenant.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: RootConfig.module.title,
            },
        },
        groups: [
            {
                id: 'basic-info',
                title: `@${i18n}.groups.basic-info`,
            },
            {
                id: 'branding',
                title: `@${i18n}.groups.branding`,
            },
            {
                id: 'contact-info',
                title: `@${i18n}.groups.contact-info`,
            },
            {
                id: 'location-info',
                title: `@${i18n}.groups.location-info`,
            },
            {
                id: 'domain-info',
                title: `@${i18n}.groups.domain-info`,
            },
            {
                id: 'administrative',
                title: `@${i18n}.groups.administrative`,
            },
        ],
        properties: [
            {
                name: 'name',
                title: `@${i18n}.fields.name.title`,
                groupId: 'basic-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.name.placeholder`,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'title',
                title: `@${i18n}.fields.title.title`,
                groupId: 'basic-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.title.placeholder`,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: '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: AXPWidgetsCatalog.largeText,
                        options: {
                            placeholder: `@${i18n}.fields.description.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'email',
                title: `@${i18n}.fields.email.title`,
                groupId: 'contact-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.email.placeholder`,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'email',
                    },
                ],
            },
            {
                name: 'phone',
                title: `@${i18n}.fields.phone.title`,
                groupId: 'contact-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.phone.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'website',
                title: `@${i18n}.fields.website.title`,
                groupId: 'contact-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: false,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.website.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'supportEmail',
                title: `@${i18n}.fields.support-email.title`,
                groupId: 'contact-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: false,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.support-email.placeholder`,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'email',
                    },
                ],
            },
            {
                name: 'countryId',
                title: `@${i18n}.fields.country.title`,
                groupId: 'location-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.geographicRegion.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'country.id' },
                                { source: 'title', target: 'country.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'stateId',
                title: `@${i18n}.fields.state.title`,
                groupId: 'location-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.geographicRegion.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'state.id' },
                                { source: 'title', target: 'state.title' },
                            ],
                            filter: {
                                logic: 'and',
                                filters: [
                                    { field: 'parentId', operator: { type: 'equal' }, value: '{{ context.eval("countryId") }}' },
                                    { field: 'type.code', operator: { type: 'equal' }, value: 'state' },
                                ],
                            },
                            triggers: [{ event: "{{ events.context('countryId') }}", action: `{{ widget.refresh() }}` }],
                        },
                    },
                },
            },
            {
                name: 'cityId',
                title: `@${i18n}.fields.city.title`,
                groupId: 'location-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.geographicRegion.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'city.id' },
                                { source: 'title', target: 'city.title' },
                            ],
                            filter: {
                                logic: 'and',
                                filters: [
                                    { field: 'parentId', operator: { type: 'equal' }, value: '{{ context.eval("stateId") }}' },
                                    { field: 'type.code', operator: { type: 'equal' }, value: 'city' },
                                ],
                            },
                            triggers: [{ event: "{{ events.context('stateId') }}", action: `{{ widget.refresh() }}` }],
                        },
                    },
                },
            },
            {
                name: 'timezone',
                title: `@${i18n}.fields.timezone.title`,
                groupId: 'location-info',
                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.timezones.name}`,
                            textField: 'title',
                            valueField: 'code',
                            look: 'select',
                            expose: [
                                { source: 'code', target: 'timezone.code' },
                                { source: 'title', target: 'timezone.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'language',
                title: `@${i18n}.fields.language.title`,
                groupId: 'location-info',
                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.locales.name}`,
                            textField: 'title',
                            valueField: 'code',
                            look: 'select',
                            expose: [
                                { source: 'code', target: 'language.code' },
                                { source: 'title', target: 'language.title' },
                            ],
                        },
                    },
                },
            },
            {
                name: 'domain',
                title: `@${i18n}.fields.domain.title`,
                groupId: 'domain-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.domain.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'subdomain',
                title: `@${i18n}.fields.subdomain.title`,
                groupId: 'domain-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: `@${i18n}.fields.subdomain.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'registrationDate',
                title: `@${i18n}.fields.registration-date.title`,
                groupId: 'administrative',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                        options: {
                            showTime: false,
                        },
                    },
                },
            },
            {
                name: 'expiryDate',
                title: `@${i18n}.fields.expiry-date.title`,
                groupId: 'administrative',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                        options: {
                            showTime: false,
                        },
                    },
                },
            },
            {
                name: 'maxUsers',
                title: `@${i18n}.fields.max-users.title`,
                groupId: 'administrative',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            minValue: 0,
                            placeholder: `@${i18n}.fields.max-users.placeholder`,
                        },
                    },
                },
            },
            {
                name: 'maxStorage',
                title: `@${i18n}.fields.max-storage.title`,
                groupId: 'administrative',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                        options: {
                            minValue: 0,
                            placeholder: `@${i18n}.fields.max-storage.placeholder`,
                        },
                    },
                },
            },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.subscription.name}`,
                title: `@${RootConfig.config.i18n}:tenants.entities.related-entities.subscriptions.title`,
                icon: RootConfig$1.entities.subscription.icon,
                columns: ['planId', 'statusId', 'startDate', 'endDate'],
                conditions: [
                    { name: 'subscriberType', operator: { type: 'equal' }, value: 'Tenant' },
                    { name: 'subscriberId', operator: { type: 'equal' }, value: '{{ context.eval("id") }}' },
                ],
                actions: [...entityDetailsCrudActions('subscriberId')],
                layout: { type: 'page-list', position: 'after', order: 1 },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.tenantUser.name}`,
                title: `@${RootConfig.config.i18n}:tenants.entities.related-entities.tenant-users.title`,
                icon: RootConfig.entities.tenantUser.icon,
                columns: ['userId', 'roleId', 'statusId', 'startDate', 'endDate', 'isAccountHolder'],
                conditions: [
                    { name: 'tenantId', operator: { type: 'equal' }, value: '{{ context.eval("id") }}' },
                ],
                actions: [
                    ...entityDetailsCrudActions('tenantId'),
                    {
                        name: 'create-tenant-user',
                        title: '@tenant-management:tenants.actions.create-tenant-user.title',
                        icon: 'fa-light fa-user-plus',
                        command: {
                            name: 'TenantManagement.Tenant:CreateTenantUser',
                            options: {
                                tenantId: '{{ context.eval("id") }}',
                            },
                        },
                        priority: 'primary',
                        type: AXPSystemActionType.Create,
                        scope: AXPEntityCommandScope.TypeLevel,
                    },
                ],
                layout: { type: 'page-list', position: 'after', order: 2 },
            },
        ],
        columns: [
            { name: 'name' },
            { name: 'title' },
            { name: 'statusId' },
            { name: 'email' },
            { name: 'domain' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'branding' },
                        { id: 'contact-info' },
                        { id: 'location-info' },
                        { id: 'domain-info' },
                        { id: 'administrative' },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'email', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'phone', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'website', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'supportEmail', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'countryId', layout: { positions: { lg: { colSpan: 4, order: 1 } } } },
                        { name: 'stateId', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'cityId', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'timezone', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'language', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'domain', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'subdomain', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'registrationDate', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'expiryDate', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'maxUsers', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'maxStorage', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-info' },
                        { id: 'branding' },
                        { id: 'contact-info' },
                        { id: 'location-info' },
                        { id: 'domain-info' },
                        { id: 'administrative' },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'email', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'phone', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'website', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'supportEmail', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'countryId', layout: { positions: { lg: { colSpan: 4, order: 1 } } } },
                        { name: 'stateId', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'cityId', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'timezone', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'language', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'domain', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'subdomain', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'registrationDate', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'expiryDate', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'maxUsers', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'maxStorage', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'branding', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'contact-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'location-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'domain-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'administrative', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'email', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'phone', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'website', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'supportEmail', layout: { positions: { lg: { colSpan: 12, order: 4 } } } },
                        { name: 'countryId', layout: { positions: { lg: { colSpan: 4, order: 1 } } } },
                        { name: 'stateId', layout: { positions: { lg: { colSpan: 4, order: 2 } } } },
                        { name: 'cityId', layout: { positions: { lg: { colSpan: 4, order: 3 } } } },
                        { name: 'timezone', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'language', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'domain', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'subdomain', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'expiryDate', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'maxUsers', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'maxStorage', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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

//#region ----   Imports   ----
//#endregion
//#region ----   Tenant User Entity Factory   ----
async function tenantUserEntityFactory(injector) {
    const i18n = RootConfig.config.i18n + ':tenants.entities.tenant-user';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.tenantUser.name,
        title: RootConfig.entities.tenantUser.title,
        icon: RootConfig.entities.tenantUser.icon,
        formats: {
            individual: RootConfig.entities.tenantUser.title,
            plural: RootConfig.entities.tenantUser.titlePlural,
            searchResult: {
                title: '{{ user.displayName }} - {{ tenant.title }}',
                description: '{{ role.title }}',
            },
        },
        plugins: [
            {
                name: 'status',
                options: {
                    field: 'statusId',
                    definition: 'tenant-management.status.tenant',
                },
            },
            { name: 'history' },
            { name: 'compare' },
        ],
        groups: [
            {
                id: 'basic-info',
                title: `@${i18n}.groups.basic-info`,
            },
            {
                id: 'membership-details',
                title: `@${i18n}.groups.membership-details`,
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'basic-info',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'tenantId',
                title: `@${i18n}.fields.tenant.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.tenant.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'tenant.id' },
                                { source: 'title', target: 'tenant.title' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'userId',
                title: `@${i18n}.fields.user.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$4.module.name}.${RootConfig$4.entities.users.name}`,
                            textField: 'displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'user.id' },
                                { source: 'username', target: 'user.username' },
                                { source: 'displayName', target: 'user.displayName' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'roleId',
                title: `@${i18n}.fields.role.title`,
                groupId: 'membership-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LookupBox,
                        options: {
                            entity: `${RootConfig$4.module.name}.${RootConfig$4.entities.roles.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'role.id' },
                                { source: 'name', target: 'role.name' },
                                { source: 'title', target: 'role.title' },
                            ],
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'statusId',
                title: `@${i18n}.fields.status.title`,
                groupId: 'membership-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'id',
                            textField: 'title',
                            dataSource: [],
                        },
                    },
                },
            },
            {
                name: 'startDate',
                title: `@${i18n}.fields.start-date.title`,
                groupId: 'membership-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: 'membership-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsList.Editors.DateTimeBox,
                        options: {
                            format: 'date',
                        },
                    },
                },
            },
            {
                name: 'isAccountHolder',
                title: `@${i18n}.fields.is-account-holder.title`,
                groupId: 'membership-details',
                options: {
                    sort: { enabled: true },
                    filter: {
                        advance: { enabled: true },
                        inline: { enabled: true },
                    },
                },
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsList.Editors.CheckBox,
                        // options: {
                        //     readOnly: true,
                        // },
                    },
                },
            },
        ],
        columns: [
            { name: 'userId', options: { dataPath: 'user' } },
            { name: 'tenantId', options: { dataPath: 'tenant' } },
            { name: 'roleId', options: { dataPath: 'role' } },
            { name: 'statusId' },
            { name: 'startDate' },
            { name: 'endDate' },
            { name: 'isAccountHolder' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'membership-details',
                        },
                    ],
                    properties: [
                        {
                            name: 'tenantId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'userId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'roleId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'statusId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'startDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'endDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'isAccountHolder',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                        {
                            id: 'membership-details',
                        },
                    ],
                    properties: [
                        {
                            name: 'tenantId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'userId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'roleId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'statusId',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'startDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'endDate',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'isAccountHolder',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions({ create: false }),
                        {
                            name: 'create-tenant-user',
                            title: `@${RootConfig.config.i18n}:tenants.actions.create-tenant-user.title`,
                            icon: 'fa-light fa-user-plus',
                            command: {
                                name: 'TenantManagement.Tenant:CreateTenantUser',
                                options: {},
                            },
                            priority: 'primary',
                            type: AXPSystemActionType.Create,
                            scope: AXPEntityCommandScope.TypeLevel,
                        },
                    ],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'startDate', dir: 'desc' }],
                        }),
                    ],
                },
                single: {
                    title: '{{ user.displayName }} - {{ tenant.title }}',
                    description: '{{ role.title }}',
                    sections: [
                        { id: 'basic-info', layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'membership-details', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'tenantId', layout: { positions: { lg: { colSpan: 12, order: 1 } } } },
                        { name: 'userId', layout: { positions: { lg: { colSpan: 12, order: 2 } } } },
                        { name: 'roleId', layout: { positions: { lg: { colSpan: 12, order: 3 } } } },
                        { name: 'statusId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'startDate', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                        { name: 'endDate', layout: { positions: { lg: { colSpan: 6, order: 6 } } } },
                        { name: 'isAccountHolder', layout: { positions: { lg: { colSpan: 12, order: 7 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

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

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

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

export { AXMTenantEntityModule, AXMTenantManagementEntityProvider, AXMTenantManagementFeatureDefinitionProvider, AXMTenantManagementFeatureKeys, AXMTenantManagementMenuKeys, AXMTenantManagementModule, AXMTenantManagementModuleConst, AXMTenantManagementModuleMenuProvider, AXMTenantManagementPermissionsKeys, AXMTenantManagementTenantUserEntityService, AXMTenantManagementTenantUserEntityServiceImpl, AXMTenantSearchCommandProvider, AXMTenantService, AXMTenantServiceImpl, AXMTenantSettingProvider, AXMTenantUserEntityModule, RootConfig, tenantEntityFactory, tenantUserEntityFactory };
//# sourceMappingURL=acorex-modules-tenant-management.mjs.map
