/**
 * GET /api/jobs/<id>/runs/<runId> — { run, dispatches: [...] }
 */

import { NextResponse } from 'next/server';
import { getJob, getRun, listDispatches } from '@/lib/jobs/store';

export async function GET(_req: Request, { params }: { params: Promise<{ id: string; runId: string }> }) {
  const { id, runId } = await params;
  const job = getJob(id);
  if (!job) return NextResponse.json({ error: 'job not found' }, { status: 404 });
  const run = getRun(runId);
  if (!run || run.job_id !== id) return NextResponse.json({ error: 'run not found' }, { status: 404 });
  return NextResponse.json({ run, dispatches: listDispatches(runId) });
}
