"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.requiredTenant = requiredTenant;
const nest_auth_contracts_1 = require("@ackplus/nest-auth-contracts");
const common_1 = require("@nestjs/common");
const auth_constants_1 = require("../auth.constants");
function requiredTenant(tenantConfig, tenantId, throwError = true) {
    const tenantEnabled = tenantConfig?.enabled;
    const tenantMode = tenantConfig?.mode;
    if (throwError && tenantEnabled && tenantMode === nest_auth_contracts_1.TenantModeEnum.ISOLATED && !tenantId) {
        throw new common_1.BadRequestException({
            message: 'Tenant ID is required',
            code: auth_constants_1.ERROR_CODES.TENANT_ID_REQUIRED,
        });
    }
    if (tenantEnabled && tenantMode === nest_auth_contracts_1.TenantModeEnum.ISOLATED) {
        return true;
    }
    return false;
}
//# sourceMappingURL=tenant.js.map