import { NextRequest, NextResponse } from "next/server";
import {
  executeScript,
  getQueueStats,
} from "../../../services/bashExecService";

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const { scriptPath, args } = body;

    if (!scriptPath) {
      return NextResponse.json(
        { error: "Script path is required" },
        { status: 400 },
      );
    }

    const result = await executeScript({
      scriptPath,
      args,
    });

    return NextResponse.json(result);
  } catch (error: any) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}

// Endpoint to get queue statistics
export async function GET() {
  try {
    const stats = getQueueStats();
    return NextResponse.json(stats);
  } catch (error: any) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}
