"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TEST_WITHOUT_FLOWS_MESSAGE = void 0;
exports.resolveAllNestedFlowReferences = resolveAllNestedFlowReferences;
exports.getJourneyFlowArray = getJourneyFlowArray;
exports.TEST_WITHOUT_FLOWS_MESSAGE = `Test does not have any flows. You may need to specify a branch [--branch] if the test is not on master.`;
async function resolveAllNestedFlowReferences(topLevelFlows, apiClient, branchName) {
    const flowIds = topLevelFlows
        .map((f) => f.id)
        .filter((id) => !!id);
    if (flowIds.length === 0) {
        return [];
    }
    return apiClient.getBatchNestedFlowReferences(flowIds, branchName);
}
async function getJourneyFlowArray(journey, apiClient, branchName) {
    if (!journey.flows?.length) {
        throw new Error(exports.TEST_WITHOUT_FLOWS_MESSAGE);
    }
    const flows = {};
    const requests = journey.flows.map((flowId) => apiClient
        .getFlow(flowId, branchName)
        .then((result) => (flows[flowId] = result)));
    await Promise.all(requests);
    return journey.flows.map((flowId) => flows[flowId]).filter((flow) => flow);
}
