import { parseModelConfig, parseModelsConfig } from "./config/model.js";
import { readParsedConfigFile, resolveSummarizeConfigPath } from "./config/read.js";
import { parseApiKeysConfig, parseCacheConfig, parseCliConfig, parseEnvConfig, parseLoggingConfig, parseMediaConfig, parseOpenAiConfig, parseOutputConfig, parseProviderBaseUrlConfig, parseSlidesConfig, parseUiConfig, } from "./config/sections.js";
import { parseSpeakersConfig } from "./config/speakers.js";
export { mergeConfigEnv, resolveConfigEnv } from "./config/env.js";
export function loadSummarizeConfig({ env }) {
    const path = resolveSummarizeConfigPath(env);
    if (!path)
        return { config: null, path: null };
    const parsed = readParsedConfigFile(path);
    if (!parsed)
        return { config: null, path };
    const model = parseModelConfig(parsed.model, path, "model");
    const language = (() => {
        const value = parsed.language;
        if (typeof value === "undefined")
            return undefined;
        if (typeof value !== "string") {
            throw new Error(`Invalid config file ${path}: "language" must be a string.`);
        }
        const trimmed = value.trim();
        if (!trimmed) {
            throw new Error(`Invalid config file ${path}: "language" must not be empty.`);
        }
        return trimmed;
    })();
    const prompt = (() => {
        const value = parsed.prompt;
        if (typeof value === "undefined")
            return undefined;
        if (typeof value !== "string") {
            throw new Error(`Invalid config file ${path}: "prompt" must be a string.`);
        }
        const trimmed = value.trim();
        if (!trimmed) {
            throw new Error(`Invalid config file ${path}: "prompt" must not be empty.`);
        }
        return trimmed;
    })();
    const models = parseModelsConfig(parsed, path);
    const cache = parseCacheConfig(parsed, path);
    const media = parseMediaConfig(parsed);
    const slides = parseSlidesConfig(parsed, path);
    const speakers = parseSpeakersConfig(parsed, path);
    const cli = parseCliConfig(parsed, path);
    const output = parseOutputConfig(parsed, path);
    const ui = parseUiConfig(parsed, path);
    const logging = parseLoggingConfig(parsed, path);
    const openai = parseOpenAiConfig(parsed, path);
    const nvidia = parseProviderBaseUrlConfig(parsed.nvidia, path, "nvidia");
    const minimax = parseProviderBaseUrlConfig(parsed.minimax, path, "minimax");
    const anthropic = parseProviderBaseUrlConfig(parsed.anthropic, path, "anthropic");
    const google = parseProviderBaseUrlConfig(parsed.google, path, "google");
    const xai = parseProviderBaseUrlConfig(parsed.xai, path, "xai");
    const zai = parseProviderBaseUrlConfig(parsed.zai, path, "zai");
    const ollama = parseProviderBaseUrlConfig(parsed.ollama, path, "ollama");
    const configEnv = parseEnvConfig(parsed, path);
    const apiKeys = parseApiKeysConfig(parsed, path);
    return {
        config: {
            ...(model ? { model } : {}),
            ...(language ? { language } : {}),
            ...(prompt ? { prompt } : {}),
            ...(cache ? { cache } : {}),
            ...(models ? { models } : {}),
            ...(media ? { media } : {}),
            ...(slides ? { slides } : {}),
            ...(speakers ? { speakers } : {}),
            ...(output ? { output } : {}),
            ...(ui ? { ui } : {}),
            ...(cli ? { cli } : {}),
            ...(openai ? { openai } : {}),
            ...(nvidia ? { nvidia } : {}),
            ...(minimax ? { minimax } : {}),
            ...(anthropic ? { anthropic } : {}),
            ...(google ? { google } : {}),
            ...(xai ? { xai } : {}),
            ...(zai ? { zai } : {}),
            ...(ollama ? { ollama } : {}),
            ...(logging ? { logging } : {}),
            ...(configEnv ? { env: configEnv } : {}),
            ...(apiKeys ? { apiKeys } : {}),
        },
        path,
    };
}
//# sourceMappingURL=config.js.map