"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchActivityInputs = fetchActivityInputs;
exports.fetchActivityDetails = fetchActivityDetails;
const controlplane_1 = require("../controlplane");
/**
 * Fetch enriched activity inputs from HotMesh's stream history.
 * Returns a lookup map keyed by `name:dimension` for merging into events.
 * Best-effort — returns empty map on failure.
 */
async function fetchActivityInputs(jobId, appId) {
    const map = new Map();
    try {
        const engine = await (0, controlplane_1.getEngine)(appId);
        const exported = await engine.export(jobId, { enrich_inputs: true });
        for (const activity of exported.activities ?? []) {
            map.set(`${activity.name}:${activity.dimension}`, activity.input ?? {});
        }
    }
    catch {
        // enrichment is best-effort; continue without inputs
    }
    return map;
}
/**
 * Fetch the structured ActivityDetail array from HotMesh export.
 * Returns undefined if enrichment fails or produces no results.
 */
async function fetchActivityDetails(jobId, appId) {
    try {
        const engine = await (0, controlplane_1.getEngine)(appId);
        const exported = await engine.export(jobId, { enrich_inputs: true });
        const activities = exported.activities;
        return activities?.length ? activities : undefined;
    }
    catch {
        return undefined;
    }
}
