"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveFetcherParamsWithEnv = void 0;
const readEnv_1 = require("../env/readEnv");
const resolveFetcherParamsWithEnv = (fetcherParams, envPath) => __awaiter(void 0, void 0, void 0, function* () {
    let environment;
    if (Object.values(fetcherParams).some((value) => typeof value === 'string' && value.startsWith('env.'))) {
        environment = yield (0, readEnv_1.readEnv)(envPath);
    }
    const results = Object.entries(fetcherParams).reduce((transformedParams, [key, fetcherParamValue]) => {
        let fetcherParamCopy = fetcherParamValue;
        if (typeof fetcherParamValue === 'string') {
            if (fetcherParamValue.startsWith('env.')) {
                const paramWithoutEnv = fetcherParamValue.replace('env.', '');
                if (environment[paramWithoutEnv]) {
                    fetcherParamCopy = environment[paramWithoutEnv];
                }
            }
        }
        transformedParams[key] = fetcherParamCopy;
        return transformedParams;
    }, {});
    return results;
});
exports.resolveFetcherParamsWithEnv = resolveFetcherParamsWithEnv;
