"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _AuthError_datapoints;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthError = void 0;
const ServiceError_1 = require("./ServiceError");
const SERVICE_NAME = process.env.SERVICE_NAME || 'SERVICE_NAME_NOT_DEFINED';
const NonFactoryLock = {};
class AuthError extends ServiceError_1.ServiceError {
    constructor(message, lock, username, orgId) {
        super(401, true, message);
        _AuthError_datapoints.set(this, {});
        __classPrivateFieldGet(this, _AuthError_datapoints, "f").username = username;
        __classPrivateFieldGet(this, _AuthError_datapoints, "f").orgId = orgId;
        if (lock !== NonFactoryLock) {
            throw new Error('Don’t be lazy. Create factory function, so that we have a single place where all the possible errors are listed');
        }
    }
    static employeeLacksAuthorizationForOrg(employeeUsername, orgId) {
        return new AuthError(`AuthError: Employee lacks authorization for organization. Employee: ${employeeUsername}, organization: ${orgId}`, NonFactoryLock, employeeUsername, orgId);
    }
    toString() {
        return `AuthError in ${SERVICE_NAME}: ${this.message}`;
    }
    toErrorObject() {
        return Object.assign({ errorKind: 'AuthError', message: this.message, httpStatus: this.httpStatus, shouldTriggerInvestigation: this.shouldTriggerInvestigation }, __classPrivateFieldGet(this, _AuthError_datapoints, "f"));
    }
}
exports.AuthError = AuthError;
_AuthError_datapoints = new WeakMap();
//# sourceMappingURL=AuthError.js.map