"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 Dao {
    static get daosJsonPath() {
        return path_1.default.join(path_resolver_1.getPrjRoot(), 'daos.json');
    }
    static getList(withModule = false) {
        return __awaiter(this, void 0, void 0, function* () {
            const file = yield fs_1.promises.readFile(Dao.daosJsonPath);
            const jsonDaos = JSON.parse(file.toString());
            return jsonDaos.map(jsonDao => {
                const dao = new Dao();
                dao.id = jsonDao.id;
                dao.name = jsonDao.name;
                dao.package = jsonDao.package;
                if (withModule) {
                    dao.module = require(path_1.default.join(path_resolver_1.getNodeModulesRoot(), dao.package));
                }
                return dao;
            });
        });
    }
    getById(daoId) {
        return __awaiter(this, void 0, void 0, function* () {
            const daos = yield Dao.getList();
            const dao = daos.find(d => d.id === daoId);
            if (dao) {
                Object.assign(this, Object.assign({}, dao));
                this.module = require(path_1.default.join(path_resolver_1.getNodeModulesRoot(), this.package));
                return true;
            }
            else {
                return false;
            }
        });
    }
}
exports.default = Dao;
//# sourceMappingURL=index.js.map