/**
 * GET /api/jobs/<id>/runs?limit=20 — list runs for a job.
 */

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

export async function GET(req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const job = getJob(id);
  if (!job) return NextResponse.json({ error: 'job not found' }, { status: 404 });
  const url = new URL(req.url);
  const limit = Math.min(200, Math.max(1, Number(url.searchParams.get('limit') || 20)));
  return NextResponse.json({ runs: listRuns(id, limit) });
}
