"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rememberApp = rememberApp;
exports.getApp = getApp;
exports.configureServerFactory = configureServerFactory;
const forEach_1 = __importDefault(require("lodash/forEach"));
const constants_1 = require("./constants");
const render_layout_1 = __importDefault(require("./render-layout"));
const utils_1 = require("./utils");
let app;
function rememberApp(v) {
    if (app) {
        throw new Error('The method must not be called more than once');
    }
    app = v;
}
/**
 * @deprecated use req.ctx.config instead of App().config
 */
function getApp() {
    return app;
}
const serverFactory = {
    getExtraRootPages() {
        return [];
    },
    isLocalClusterId(cluster) {
        return (0, utils_1.isLocalModeByEnvironment)() || cluster === constants_1.YT_LOCAL_CLUSTER_ID;
    },
    getHomeRedirectedUrl() {
        return Promise.resolve(undefined);
    },
    async renderLayout(params) {
        return await (0, render_layout_1.default)(params);
    },
    createCustomVcsApi() {
        return undefined;
    },
    getAuthHeaders(type, req) {
        switch (type) {
            case 'aiChat':
                return undefined;
            case 'accountsUsageTest':
            case 'accountsUsageProd':
            case 'accessLogTest':
            case 'accessLogProd':
                return req.yt.ytApiAuthHeaders;
        }
    },
};
function configureServerFactoryItem(k, redefinition) {
    serverFactory[k] = redefinition;
}
function configureServerFactory(overrides) {
    (0, forEach_1.default)(overrides, (_v, k) => {
        const key = k;
        configureServerFactoryItem(key, overrides[key]);
    });
}
exports.default = new Proxy(serverFactory, {
    set: () => {
        throw new Error('Use configureUIFactory(...) method instead of direct modifications');
    },
});
