"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 });
exports.defineConfig = void 0;
require("./base");
const common_1 = require("@bdeefe/feishu-devtools-core/libs/config/common");
const env_1 = require("../utils/env");
const storage_1 = __importDefault(require("../utils/storage"));
const account_1 = __importDefault(require("./account"));
const dev_1 = __importDefault(require("./dev"));
const preview_1 = __importDefault(require("./preview"));
const init = (params) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b, _c;
    const firstEnvId = (_a = params === null || params === void 0 ? void 0 : params.envConfig) === null || _a === void 0 ? void 0 : _a.environments[0].id;
    if (firstEnvId) {
        const config = Object.assign(Object.assign({}, params === null || params === void 0 ? void 0 : params.envConfig), { id: (_b = params.envConfig) === null || _b === void 0 ? void 0 : _b.id, name: (_c = params.envConfig) === null || _c === void 0 ? void 0 : _c.id, renderType: 'cli' });
        yield (0, env_1.setEnv)(params.envConfig ? config : undefined);
        common_1.configManager.refresh();
        storage_1.default.refreshPath();
    }
    const dev = new dev_1.default();
    if (firstEnvId) {
        dev.updateServiceEnv(firstEnvId);
    }
    return {
        account: new account_1.default(),
        dev,
        preview: new preview_1.default(),
    };
});
exports.default = {
    init,
};
var generator_1 = require("@bdeefe/feishu-devtools-core/libs/modules/creator/generator");
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return generator_1.defineConfig; } });
