import { NextResponse } from 'next/server';
import { generateSeedanceVideo } from '@/lib/videoProviders';
import type { VideoGenerationRequest } from '@/lib/types';

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

export async function POST(req: Request) {
  const body = (await req.json()) as VideoGenerationRequest;
  try {
    return NextResponse.json(await generateSeedanceVideo(body));
  } catch (error) {
    const message = String(error);
    return NextResponse.json({ error: message }, {
      status: message.includes('SEEDANCE_API_KEY missing') ? 503 : 500,
    });
  }
}
