/**
 * MJ's built-in multi-tenancy middleware.
 *
 * Registers with key 'mj:tenantFilter' so that downstream layers (e.g., BCSaaS)
 * can replace it by registering with the same key at higher ClassFactory priority.
 *
 * Conditionally enabled via configInfo.multiTenancy?.enabled.
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { RegisterClass } from '@memberjunction/global';
import { BaseServerMiddleware } from './BaseServerMiddleware.js';
import { configInfo } from '../config.js';
import { createTenantMiddleware, createTenantPreRunViewHook, createTenantPreSaveHook } from '../multiTenancy/index.js';
let MJTenantFilterMiddleware = class MJTenantFilterMiddleware extends BaseServerMiddleware {
    get Label() { return 'mj:tenantFilter'; }
    /**
     * Only active when multiTenancy is enabled in config.
     */
    get Enabled() {
        return configInfo.multiTenancy?.enabled ?? false;
    }
    GetPostAuthMiddleware() {
        return [createTenantMiddleware(configInfo.multiTenancy)];
    }
    PreRunView(params, contextUser) {
        return createTenantPreRunViewHook(configInfo.multiTenancy)(params, contextUser);
    }
    PreSave(entity, contextUser) {
        return createTenantPreSaveHook(configInfo.multiTenancy)(entity, contextUser);
    }
};
MJTenantFilterMiddleware = __decorate([
    RegisterClass(BaseServerMiddleware, 'mj:tenantFilter')
], MJTenantFilterMiddleware);
export { MJTenantFilterMiddleware };
//# sourceMappingURL=MJTenantFilterMiddleware.js.map