import { getMockConfig, lookupMock } from './mock-types.js';
/**
 * @flowWeaver nodeType
 * @input functionId - Function ID of the workflow to invoke (e.g. "my-service/sub-workflow")
 * @input payload - Data to pass as event.data to the invoked function
 * @input [timeout] - Max wait time (e.g. "1h")
 * @output result - Return value from the invoked function
 */
export async function invokeWorkflow(execute, functionId, payload, timeout) {
    if (!execute)
        return { onSuccess: false, onFailure: false, result: {} };
    const mocks = getMockConfig();
    if (mocks) {
        // Mock mode — look up result by functionId (supports instance-qualified keys)
        const mockResult = lookupMock(mocks.invocations, functionId);
        if (mockResult !== undefined) {
            return { onSuccess: true, onFailure: false, result: mockResult };
        }
        // No mock data for this functionId — simulate failure
        return { onSuccess: false, onFailure: true, result: {} };
    }
    // Check local workflow registry (populated by executeWorkflowFromFile)
    const registry = globalThis.__fw_workflow_registry__;
    if (registry?.[functionId]) {
        try {
            const result = await registry[functionId](true, payload);
            return { onSuccess: true, onFailure: false, result: result ?? {} };
        }
        catch {
            return { onSuccess: false, onFailure: true, result: {} };
        }
    }
    // No mocks, no registry match: original no-op behavior (always succeeds)
    return { onSuccess: true, onFailure: false, result: {} };
}
//# sourceMappingURL=invoke-workflow.js.map