import { NextRequest, NextResponse } from 'next/server';
import { buildOnlineLessonAttachmentResponse } from '@/features/online-lessons/server/online-lesson-attachment-response';

type Params = { params: Promise<{ id: string }> };

export const runtime = 'nodejs';

function parseLessonId(value: string) {
  const lessonId = Number(value);
  return Number.isNaN(lessonId) ? null : lessonId;
}

export async function GET(_request: NextRequest, { params }: Params) {
  const { id } = await params;
  const lessonId = parseLessonId(id);

  if (!lessonId) {
    return NextResponse.json({ message: 'Invalid online lesson attachment request' }, { status: 400 });
  }

  return buildOnlineLessonAttachmentResponse({
    lessonId,
    disposition: 'attachment'
  });
}
