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

export async function POST(req: NextRequest) {
  try {
    const auth = req.headers.get("authorization");
    const body = await req.json();

    if (!body?.astrologerId) {
      return NextResponse.json(
        {
          message: "astrologerId is required",
          status: 400,
        },
        {
          status: 400,
        }
      );
    }

    const response = await fetch(
      "https://api.astrology.togwe.com/api/user/astrologers/getAstrologerById",
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: auth ?? "",
        },
        body: JSON.stringify({
          astrologerId: Number(body.astrologerId),
        }),
        cache: "no-store",
      }
    );

    const data = await response.json();

    return NextResponse.json(data, {
      status: response.status,
    });
  } catch (e) {
    console.error("Astrologer profile API error:", e);

    return NextResponse.json(
      {
        message: "Server Error",
        status: 500,
      },
      {
        status: 500,
      }
    );
  }
}