// This file handles the appointment booking API route.
export async function POST(req) {
  try {
    const body = await req.json();

    const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/appointmentbooking/`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        cookie: req.headers.get('cookie') || '',
      },
      body: JSON.stringify(body),
    });

    console.log(body);
    if (!response.ok) {
      const errorData = await response.json();
      return new Response(JSON.stringify({ error: errorData.error || 'Failed to book appointment' }), {
        status: response.status,
      });
    }

    const result = await response.json();
    return new Response(JSON.stringify(result), { status: 200 });
  } catch (error) {
    console.error('Error booking appointment:', error);
    return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500 });
  }
}