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 DatabaseRequestType from "../../BaseDatabase/DatabaseRequestType";
import TablePermission from "./TablePermission";
import NotAuthenticatedException from "../../../../Types/Exception/NotAuthenticatedException";
import CaptureSpan from "../../../Utils/Telemetry/CaptureSpan";
import Permission from "../../../../Types/Permission";
import UserType from "../../../../Types/UserType";
export default class PublicPermission {
    static isPublicPermissionAllowed(modelType, type) {
        let isPublicAllowed = false;
        isPublicAllowed = TablePermission.getTablePermission(modelType, type).includes(Permission.Public);
        return isPublicAllowed;
    }
    static checkIfUserIsLoggedIn(modelType, props, type) {
        // 1 CHECK: PUBLIC check -- Check if this is a public request and if public is allowed.
        if (!this.isPublicPermissionAllowed(modelType, type) && !props.userId) {
            if (props.userType === UserType.API) {
                // if its an API request then continue.
                return;
            }
            // this means the record is not publicly createable and the user is not logged in.
            throw new NotAuthenticatedException(`A user should be logged in to ${type} record of ${new modelType().singularName}.`);
        }
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Boolean)
], PublicPermission, "isPublicPermissionAllowed", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object, String]),
    __metadata("design:returntype", void 0)
], PublicPermission, "checkIfUserIsLoggedIn", null);
//# sourceMappingURL=PublicPermission.js.map