"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateFingerprintConfig = void 0;
const config_1 = require("../../../config");
const manager_1 = require("../../../modules/manager");
const custom_1 = require("../../../modules/manager/custom");
const utils_1 = require("../../../modules/manager/custom/regex/utils");
function getRegexManagerFields(config) {
    const regexFields = {};
    for (const field of utils_1.validMatchFields.map((f) => `${f}Template`)) {
        if (config[field]) {
            regexFields[field] = config[field];
        }
    }
    return {
        autoReplaceStringTemplate: config.autoReplaceStringTemplate,
        matchStrings: config.matchStrings,
        matchStringsStrategy: config.matchStringsStrategy,
        ...regexFields,
    };
}
function getFilteredManagerConfig(config) {
    return {
        ...((0, custom_1.isCustomManager)(config.manager) && getRegexManagerFields(config)),
        manager: config.manager,
        fileMatch: config.fileMatch,
        npmrc: config.npmrc,
        npmrcMerge: config.npmrcMerge,
        enabled: config.enabled,
        ignorePaths: config.ignorePaths ?? [],
        includePaths: config.includePaths ?? [],
        skipInstalls: config.skipInstalls,
        registryAliases: config.registryAliases,
        fileList: [],
    };
}
function generateFingerprintConfig(config) {
    const managerExtractConfigs = [];
    let managerList;
    const { enabledManagers } = config;
    if (enabledManagers?.length) {
        managerList = new Set(enabledManagers);
    }
    else {
        managerList = new Set(manager_1.allManagersList);
    }
    for (const manager of managerList) {
        const managerConfig = (0, config_1.getManagerConfig)(config, manager);
        if ((0, custom_1.isCustomManager)(manager)) {
            // TODO: filter regexManagers using customType
            for (const regexManager of config.regexManagers ?? []) {
                managerExtractConfigs.push({
                    ...(0, config_1.mergeChildConfig)(managerConfig, regexManager),
                    fileList: [],
                });
            }
        }
        else {
            managerExtractConfigs.push({ ...managerConfig, fileList: [] });
        }
    }
    return {
        managerList,
        managers: managerExtractConfigs.map(getFilteredManagerConfig),
    };
}
exports.generateFingerprintConfig = generateFingerprintConfig;
//# sourceMappingURL=extract-fingerprint-config.js.map