//#region imports
import { CoreModels__NS__GitConnectionArr, UtilsOs__NS__EditorArr } from 'tnp-core/lib-prod';
import { HelpersTaon__NS__consoleGui__NS__select } from '../index';
import { BaseDb } from './classes/base-db';
//#endregion
const defaultDb = {
    config: {},
};
//#region config database ext
export class ConfigDatabaseEx {
    KEY_PATH_DB;
    configDb;
    constructor(KEY_PATH_DB, configDb) {
        this.KEY_PATH_DB = KEY_PATH_DB;
        this.configDb = configDb;
    }
    //#region get value
    async getValue() {
        //#region @backendFunc
        const db = await this.configDb.getConnection();
        let editor = db.data.config[this.KEY_PATH_DB];
        return editor;
        //#endregion
    }
    //#endregion
    //#region set value
    async setValue(v) {
        //#region @backendFunc
        const db = await this.configDb.getConnection();
        await db.update(data => (data.config[this.KEY_PATH_DB] = v));
        return v;
        //#endregion
    }
    //#endregion
    //#region select one value
    async selectOneValue(arrOfValues, question = 'Select default global value') {
        //#region @backendFunc
        let value = await HelpersTaon__NS__consoleGui__NS__select(question, arrOfValues.map(name => {
            return {
                name,
                value: name,
            };
        }));
        return value;
        //#endregion
    }
}
//#endregion
//#region code editor config
export class CodeEditorConfig extends ConfigDatabaseEx {
    async getValue() {
        //#region @backendFunc
        let editor = await super.getValue();
        if (!editor) {
            editor = await this.selectCodeEditor();
        }
        return editor;
        //#endregion
    }
    async selectCodeEditor() {
        //#region @backendFunc
        let editor = await this.selectOneValue(UtilsOs__NS__EditorArr, 'Select default code editor');
        await this.setValue(editor);
        return editor;
        //#endregion
    }
}
//#endregion
//#region ssh https preference config
export class SshHttpsPreferenceConfig extends ConfigDatabaseEx {
    async getValue() {
        //#region @backendFunc
        let editor = await super.getValue();
        if (!editor) {
            editor = await this.selectHttpOrSsh();
        }
        return editor;
        //#endregion
    }
    async selectHttpOrSsh() {
        //#region @backendFunc
        let editor = await this.selectOneValue(CoreModels__NS__GitConnectionArr, 'Select  default git connection type');
        await this.setValue(editor);
        return editor;
        //#endregion
    }
}
//#endregion
export class ConfigDatabase extends BaseDb {
    constructor(ins) {
        super(ins, 'config', defaultDb);
        // const editor = await this.codeEditor.getValue
    }
    codeEditor = new CodeEditorConfig('selected-code-editor', this);
    httpOrHttps = new CodeEditorConfig('selected-git-connection-type', this);
}
//# sourceMappingURL=c:/Users/darek/projects/npm/taon-dev/tnp-helpers/dist-nocutsrc-prod/lib/base/config-database.js.map