import { NextRequest, NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

// Map lesson IDs to self-hosted video files (downloaded from HeyGen)
const VIDEO_MAP: Record<string, { file: string; duration: number }> = {
  'orientation':      { file: '/videos/academy/orientation.mp4',      duration: 50 },
  'intake':           { file: '/videos/academy/intake.mp4',           duration: 44 },
  'entity-modeling':  { file: '/videos/academy/entity-modeling.mp4',  duration: 42 },
  'weft-engine':      { file: '/videos/academy/weft-engine.mp4',      duration: 46 },
  'sentinel':         { file: '/videos/academy/sentinel.mp4',         duration: 44 },
  'rag-retrieval':    { file: '/videos/academy/rag-retrieval.mp4',    duration: 41 },
  'quality-gates':    { file: '/videos/academy/quality-gates.mp4',    duration: 43 },
  'deployment':       { file: '/videos/academy/deployment.mp4',       duration: 39 },
  'constitutional-ai':{ file: '/videos/academy/constitutional-ai.mp4', duration: 45 },
  'capstone':         { file: '/videos/academy/capstone.mp4',         duration: 48 },
  // Easter eggs
  'weird-syndicate':  { file: '/videos/academy/weird-syndicate.mp4',  duration: 307 },
};

export async function GET(request: NextRequest) {
  const lessonId = request.nextUrl.searchParams.get('lessonId');
  if (!lessonId || !VIDEO_MAP[lessonId]) {
    return NextResponse.json({ error: 'Invalid lesson ID' }, { status: 400 });
  }

  const video = VIDEO_MAP[lessonId];

  return NextResponse.json({
    videoUrl: video.file,
    thumbnailUrl: null,
    duration: video.duration,
  });
}
