"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyAppEnvToConfig = applyAppEnvToConfig;
const expresskit_1 = require("@gravity-ui/expresskit");
const apply_missing_fields_1 = require("./apply-missing-fields");
function applyEnvToUISettings(config) {
    if (!config.uiSettings) {
        Object.assign(config, { uiSettings: {} });
    }
    const tmp = {
        uploadTableExcelBaseUrl: process.env.YTFRONT_UPLOAD_EXCEL_BASE_URL,
        exportTableBaseUrl: process.env.YTFRONT_EXPORT_EXCEL_BASE_URL,
        jupyterBasePath: process.env.YTFRONT_JUPYTER_BASE_URL,
        grafanaBaseUrl: process.env.GRAFANA_BASE_URL,
        docsBaseUrl: process.env.YT_DOCS_BASE_URL || 'https://ytsaurus.tech/docs/en',
    };
    (0, apply_missing_fields_1.applyMissingFields)(config.uiSettings, tmp);
}
function applyEnvToConfig(config) {
    const tmp = {
        prometheusBaseUrl: process.env.PROMETHEUS_BASE_URL,
    };
    (0, apply_missing_fields_1.applyMissingFields)(config, tmp);
}
function applyAppAuthEnvToConfig(config) {
    const { ALLOW_PASSWORD_AUTH, WITH_AUTH, YT_AUTH_CLUSTER_ID, YT_AUTH_ALLOW_INSECURE } = process.env;
    const allowPasswordAuth = Boolean(ALLOW_PASSWORD_AUTH || WITH_AUTH || YT_AUTH_CLUSTER_ID);
    const tmp = {
        allowPasswordAuth,
        ytAuthAllowInsecure: Boolean(YT_AUTH_ALLOW_INSECURE),
        ...{ appAuthPolicy: allowPasswordAuth ? expresskit_1.AuthPolicy.required : expresskit_1.AuthPolicy.disabled },
    };
    (0, apply_missing_fields_1.applyMissingFields)(config, tmp);
}
function applyAppEnvToConfig(config) {
    applyEnvToUISettings(config);
    applyEnvToConfig(config);
    applyAppAuthEnvToConfig(config);
    return config;
}
