export function collectAutomationSources(jobs, runs) {
    const sources = new Map();
    for (const job of jobs) {
        sources.set(job.source.id, job.source);
    }
    for (const run of runs) {
        if (!run.triggeredBy?.id)
            continue;
        sources.set(run.triggeredBy.id, run.triggeredBy);
    }
    return [...sources.values()];
}
export function syncAutomationRuntimeSnapshot(runtimeDispatch, jobs, runs) {
    if (!runtimeDispatch)
        return;
    for (const source of collectAutomationSources(jobs, runs)) {
        runtimeDispatch.syncAutomationSource(source, 'automation.bootstrap');
    }
    for (const job of jobs) {
        runtimeDispatch.syncAutomationJob(job, 'automation.bootstrap');
    }
    for (const run of runs) {
        runtimeDispatch.syncAutomationRun(run, 'automation.bootstrap');
    }
}
export function syncAutomationJobToRuntime(runtimeDispatch, job, source) {
    runtimeDispatch?.syncAutomationSource(job.source, `${source}.source`);
    runtimeDispatch?.syncAutomationJob(job, source);
}
export function syncAutomationRunToRuntime(runtimeDispatch, run, source) {
    runtimeDispatch?.syncAutomationSource(run.triggeredBy, `${source}.source`);
    runtimeDispatch?.syncAutomationRun(run, source);
}
