"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
class BaseModel {
    constructor() {
        this.cls = this.constructor;
    }
    static get model() {
        throw new Error('BaseModel "static get model()" not implemented!');
    }
    toConfigEntry() {
        return __awaiter(this, void 0, void 0, function* () {
            throw new Error('BaseModel "async toConfigEntry()" not implemented!');
        });
    }
    fromConfigEntry(entry) {
        return __awaiter(this, void 0, void 0, function* () {
            throw new Error('BaseModel "async fromConfigEntry(entry)" not implemented!');
        });
    }
    static _fromConfigEntry(entry) {
        return __awaiter(this, void 0, void 0, function* () {
            const e = new this();
            yield e.fromConfigEntry(entry);
            return e;
        });
    }
    static getById(id) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!id) {
                return null;
            }
            const entry = yield this.model.getEntryById(id);
            return !!entry ? yield this._fromConfigEntry(entry) : null;
        });
    }
    static getList() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.model.read();
            let entries = yield Promise.all(this.model.entries.map(this._fromConfigEntry.bind(this)));
            return entries;
        });
    }
    add() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.cls.model.addEntry(yield this.toConfigEntry());
        });
    }
    remove() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.cls.model.removeEntryById(this.id);
        });
    }
    update() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.cls.model.updateEntry(yield this.toConfigEntry());
        });
    }
}
exports.default = BaseModel;
//# sourceMappingURL=index.js.map