"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeFGData = exports.getFGData = exports.writeUpdateData = exports.fetchUpdateData = void 0;
const index_1 = __importDefault(require("../../core/libs/utils/update/index"));
const axios_1 = __importDefault(require("axios"));
const config_1 = __importDefault(require("./config"));
class CliUpdate extends index_1.default {
    constructor() {
        super({ config: config_1.default });
    }
    async fetchDebugTemplateMeta() {
        const url = process.env.DEBUG_TEMPLATES_ROOT;
        if (!url) {
            throw new Error(JSON.stringify({
                msg: 'can not find DEBUG_TEMPLATES_ROOT in env variables',
            }));
        }
        const response = await axios_1.default.get(url);
        if (response.status === 200 && response.data) {
            const config = response.data;
            return config;
        }
        else {
            throw new Error(JSON.stringify({ msg: 'fetch template meta error' }));
        }
    }
    async writeDebugTemplateMeta() {
        this.debugTemplateMeta = await this.fetchDebugTemplateMeta();
    }
    getUpdateData() {
        const data = super.getUpdateData();
        if (this.debugTemplateMeta) {
            data.cli.templateMeta = this.debugTemplateMeta;
        }
        return data;
    }
}
const update = new CliUpdate();
exports.fetchUpdateData = update.fetchUpdateData.bind(update);
exports.writeUpdateData = update.writeUpdateData.bind(update);
exports.getFGData = update.getFGData.bind(update);
exports.writeFGData = update.writeFGData.bind(update);
exports.default = update;
