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

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

export async function PATCH(request: NextRequest) {
  try {
    const response = await fetch(`${API}/auth/me/password`, {
      method: 'PATCH',
      headers: { 'Content-Type': 'application/json', Cookie: request.headers.get('cookie') ?? '' },
      body: await request.text(),
    });
    const data = await response.json().catch(() => ({}));
    return NextResponse.json(data, { status: response.status });
  } catch {
    return NextResponse.json({ error: { message: 'Error del servidor' } }, { status: 500 });
  }
}
