"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ltSignalParent = ltSignalParent;
exports.ltStartWorkflow = ltStartWorkflow;
const hotmesh_1 = require("@hotmeshio/hotmesh");
const db_1 = require("../../../lib/db");
const defaults_1 = require("../../../modules/defaults");
const logger_1 = require("../../../lib/logger");
/**
 * Signal an orchestrator workflow from within the interceptor.
 * Used after a child workflow succeeds to send the result back
 * to the awaiting orchestrator via its waitFor signal.
 */
async function ltSignalParent(input) {
    const client = new hotmesh_1.Durable.Client({
        connection: (0, db_1.getConnection)(),
    });
    const handle = await client.workflow.getHandle(input.parentTaskQueue, input.parentWorkflowType, input.parentWorkflowId);
    await handle.signal(input.signalId, input.data);
}
/**
 * Start a workflow from within an activity context.
 * Used by the triage orchestrator to auto-resolve: directly re-run the
 * original workflow with correctedData as the resolver, bypassing the
 * "create escalation → human resolves → re-run" cycle for high-confidence
 * pass-through cases.
 */
async function ltStartWorkflow(input) {
    const client = new hotmesh_1.Durable.Client({
        connection: (0, db_1.getConnection)(),
    });
    await client.workflow.start({
        workflowName: input.workflowName,
        args: input.args,
        taskQueue: input.taskQueue,
        workflowId: input.workflowId,
        expire: input.expire ?? defaults_1.JOB_EXPIRE_SECS,
        signalIn: false,
    });
    logger_1.loggerRegistry.info(`[ltStartWorkflow] started ${input.workflowName} (${input.workflowId})`);
}
