export async function POST(req) {
  try {
    const body = await req.json();
    const { consultationId, status } = body;
    if (!consultationId || !['active', 'completed'].includes(status)) {
      return new Response(
        JSON.stringify({ error: 'Invalid consultation ID or status' }),
        { status: 400 }
      );
    }

    // Send the request to backend server
    const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/changestatus`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        cookie: req.headers.get('cookie') || '',
      },
      body: JSON.stringify({ consultationId, status }),
    });

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

    const result = await response.json();
    return new Response(JSON.stringify(result), { status: 200 });

  } catch (error) {
    console.error('Error changing consultation status:', error);
    return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500 });
  }
}
