import { NextResponse } from 'next/server';

const TRIP_SERVICE_URL = 'http://trip-service.ai-agents.svc.cluster.local:6002';

export async function GET() {
  try {
    const res = await fetch(`${TRIP_SERVICE_URL}/trips`, { cache: 'no-store' });
    const data = await res.json();
    return NextResponse.json(data);
  } catch (error) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}

export async function POST(req) {
  try {
    const body = await req.json();
    const res = await fetch(`${TRIP_SERVICE_URL}/trips`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(body)
    });
    const data = await res.json();
    return NextResponse.json(data);
  } catch (error) {
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}
