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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { IsBillingEnabled, IsEnterpriseEdition, } from "../../../../Server/EnvironmentConfig";
import PaymentRequiredException from "../../../../Types/Exception/PaymentRequiredException";
import CaptureSpan from "../../../Utils/Telemetry/CaptureSpan";
export default class EditionPermissions {
    /*
     * Gates models marked with @TableEditionAccessControl({ requiresEnterprise: true }).
     *
     * On self-hosted builds (billing disabled) the model is only accessible when
     * the binary was built as the Enterprise Edition (IS_ENTERPRISE_EDITION=true).
     *
     * On the cloud / billing-enabled deployment we leave enforcement to
     * BillingPermission — it already gates these models via the model's
     * @TableBillingAccessControl plan tier, so a second check would be redundant.
     */
    static checkEditionPermissions(modelType, _props) {
        if (IsBillingEnabled) {
            return;
        }
        const model = new modelType();
        if (!model.requiresEnterprise) {
            return;
        }
        if (!IsEnterpriseEdition) {
            throw new PaymentRequiredException(`${model.singularName || "This feature"} is only available on the OneUptime Enterprise Edition. ` +
                `Please switch to the Enterprise Edition build to enable this feature. ` +
                `See https://oneuptime.com/enterprise/overview for details.`);
        }
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", void 0)
], EditionPermissions, "checkEditionPermissions", null);
//# sourceMappingURL=EditionPermission.js.map