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

const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const backendRes = await fetch(`${API}/auth/password-reset/request`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', 'x-forwarded-for': request.headers.get('x-forwarded-for') ?? '' },
      body: JSON.stringify(body),
    });
    const data = await backendRes.json().catch(() => ({ error: { message: 'Error del servidor' } }));
    return NextResponse.json(data, { status: backendRes.status });
  } catch {
    return NextResponse.json({ error: { message: 'Error del servidor' } }, { status: 500 });
  }
}
