"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const path_resolver_1 = require("root/services/path-resolver");
class Authorizer {
    static get authorizersJsonPath() {
        return path_1.default.join(path_resolver_1.getPrjRoot(), 'authorizers.json');
    }
    static getList() {
        return __awaiter(this, void 0, void 0, function* () {
            const file = yield fs_1.promises.readFile(Authorizer.authorizersJsonPath);
            const jsonAuthorizers = JSON.parse(file.toString());
            return jsonAuthorizers.map(jsonAuthorizer => {
                const authorizer = new Authorizer();
                authorizer.id = jsonAuthorizer.id;
                authorizer.name = jsonAuthorizer.name;
                authorizer.package = jsonAuthorizer.package;
                authorizer.sessionModelName = jsonAuthorizer.sessionModelName;
                return authorizer;
            });
        });
    }
    getById(authorizerId) {
        return __awaiter(this, void 0, void 0, function* () {
            const authorizers = yield Authorizer.getList();
            const authorizer = authorizers.find(d => d.id === authorizerId);
            if (authorizer) {
                Object.assign(this, Object.assign({}, authorizer));
                return true;
            }
            else {
                return false;
            }
        });
    }
}
exports.default = Authorizer;
//# sourceMappingURL=index.js.map