/**
 * GET /api/rmm/executions/:id
 *
 * Returns one execution row including stdout / stderr / parsed_evidence.
 * Used by the live-stream UI to poll status.
 */

import { NextRequest, NextResponse } from 'next/server';
import { requireAuth } from '@/lib/auth-utils';
import { getExecutionById } from '@/lib/services/rmm/persistence';

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  const { error } = await requireAuth();
  if (error) return error;
  const { id } = await params;
  const execution = await getExecutionById(id);
  if (!execution) {
    return NextResponse.json({ error: 'Execution not found' }, { status: 404 });
  }
  return NextResponse.json({ execution });
}
