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

export async function POST(req: NextRequest) {
  try {
    const body = await req.json(); // Extract the request body

    // Forward the registration request to your FastAPI backend
    const response = await fetch(`${process.env.API_URL}/api/v1/register`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(body),
    });

    const data = await response.json();

    if (!response.ok) {
      return NextResponse.json({ error: data.detail || 'Failed to register' }, { status: response.status });
    }

    return NextResponse.json({ message: 'User registered successfully', user: data }, { status: 201 });
  } catch (error) {
    console.error('Error during registration:', error);
    return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
  }
}