// GET /api/hail/engagements/[id]  — engagement detail + its interviews (practitioner only)

import { getEngagement } from '../../../../../lib/hail/engagements.js';
import { listInterviews } from '../../../../../lib/hail/interview.js';
import { requirePractitioner, errorResponse } from '../../guard.js';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function GET(req, { params }) {
  const { id } = await params;
  try {
    await requirePractitioner(req);
    const engagement = getEngagement(id);
    if (!engagement) return Response.json({ error: 'engagement_not_found' }, { status: 404 });
    return Response.json({ engagement, interviews: listInterviews(id) });
  } catch (err) {
    return errorResponse(err);
  }
}
