"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultConfiguration = exports.getConfigFromEnvironmentVariables = exports.ConfigSchema = void 0;
const zod_1 = require("zod");
exports.ConfigSchema = zod_1.z
    .object({
    // Glob pattern for finding and parsing shell script files in the workspace. Used by the background analysis features across files.
    globPattern: zod_1.z.string().trim().default('**/*@(.sh|.inc|.bash|.command)'),
    // Controls if Treesitter parsing errors will be highlighted as problems.
    highlightParsingErrors: zod_1.z.boolean().default(false),
    // Configure explainshell server endpoint in order to get hover documentation on flags and options.
    // And empty string will disable the feature.
    explainshellEndpoint: zod_1.z.string().trim().default(''),
    // Controls the executable used for ShellCheck linting information. An empty string will disable linting.
    shellcheckPath: zod_1.z.string().trim().default('shellcheck'),
    // Additional ShellCheck arguments. Note that we already add the following arguments: --shell, --format, --external-sources."
    shellcheckArguments: zod_1.z
        .preprocess((arg) => {
        let argsList = [];
        if (typeof arg === 'string') {
            argsList = arg.split(' ');
            //.map((s) => s.trim())
            //.filter((s) => s.length > 0)
        }
        else if (Array.isArray(arg)) {
            argsList = arg;
        }
        return argsList.map((s) => s.trim()).filter((s) => s.length > 0);
    }, zod_1.z.array(zod_1.z.string()))
        .default([]),
    // Maximum number of files to analyze in the background. Set to 0 to disable background analysis.
    backgroundAnalysisMaxFiles: zod_1.z.number().int().min(0).default(500),
})
    .strict();
function getConfigFromEnvironmentVariables() {
    const { HIGHLIGHT_PARSING_ERRORS } = process.env;
    const rawConfig = {
        globPattern: process.env.GLOB_PATTERN,
        highlightParsingErrors: typeof HIGHLIGHT_PARSING_ERRORS !== 'undefined'
            ? toBoolean(HIGHLIGHT_PARSING_ERRORS)
            : undefined,
        explainshellEndpoint: process.env.EXPLAINSHELL_ENDPOINT,
        shellcheckPath: process.env.SHELLCHECK_PATH,
        shellcheckArguments: process.env.SHELLCHECK_ARGUMENTS,
        backgroundAnalysisMaxFiles: process.env.BACKGROUND_ANALYSIS_MAX_FILES,
    };
    const environmentVariablesUsed = Object.entries(rawConfig)
        .map(([key, value]) => (typeof value !== 'undefined' ? key : null))
        .filter((key) => key !== null);
    const config = exports.ConfigSchema.parse(rawConfig);
    return { config, environmentVariablesUsed };
}
exports.getConfigFromEnvironmentVariables = getConfigFromEnvironmentVariables;
function getDefaultConfiguration() {
    return exports.ConfigSchema.parse({});
}
exports.getDefaultConfiguration = getDefaultConfiguration;
const toBoolean = (s) => s === 'true' || s === '1';
//# sourceMappingURL=config.js.map