/**
 * POST /api/ticket-workflows/:id/test - Dry-run test workflow on a ticket
 */

import { NextRequest, NextResponse } from 'next/server';
import { ticketWorkflowEngine } from '@/lib/services/ticket-workflow-engine';

export async function POST(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const { id } = await params;
    const body = await request.json();
    const { ticket_id } = body;

    if (!ticket_id) {
      return NextResponse.json(
        { error: 'Missing required field: ticket_id' },
        { status: 400 }
      );
    }

    const result = await ticketWorkflowEngine.dryRun(Number(id), Number(ticket_id));

    return NextResponse.json(result);
  } catch (error) {
    console.error('[API] Error running workflow test:', error);
    return NextResponse.json(
      { error: error instanceof Error ? error.message : 'Failed to run test' },
      { status: 500 }
    );
  }
}
