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

import { getCreatorCV } from '@/services/creators';

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams;
    const personId = searchParams.get('personId');

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

    const cv = await getCreatorCV(personId);
    return NextResponse.json({ cv }, { status: 200 });
  } catch (error) {
    console.error('Error fetching CV:', error);
    return NextResponse.json({ error: 'Failed to fetch CV' }, { status: 500 });
  }
}
