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

const GATEWAY_HOST = 'http://kt-event-marketing-api.20.214.196.128.nip.io';

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

    console.log('🔐 [Proxy] Login request:', {
      email: body.email,
      timestamp: new Date().toISOString(),
    });

    const response = await fetch(`${GATEWAY_HOST}/api/v1/users/login`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(body),
    });

    const data = await response.json();

    console.log('📥 [Proxy] Login response:', {
      status: response.status,
      success: response.ok,
    });

    if (!response.ok) {
      return NextResponse.json(data, { status: response.status });
    }

    return NextResponse.json(data);
  } catch (error) {
    console.error('❌ [Proxy] Login error:', error);
    return NextResponse.json(
      { message: '로그인 요청 중 오류가 발생했습니다.' },
      { status: 500 }
    );
  }
}
