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

const CREATE_ORDER_API = "https://api.astrology.togwe.com/api/user/wallet/create-order";

export async function POST(request: NextRequest) {
  try {
    const authorization = request.headers.get("authorization");

    if (!authorization) {
      return NextResponse.json(
        { status: false, message: "Authentication token is required." },
        { status: 401 },
      );
    }

    const body = await request.json();

    const response = await fetch(CREATE_ORDER_API, {
      method: "POST",

      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
        Authorization: authorization,
      },

      body: JSON.stringify(body),

      cache: "no-store",
    });

    const data = await response.json();

    return NextResponse.json(data, { status: response.status });
  } catch (error) {
    console.error("Wallet create-order proxy error:", error);

    return NextResponse.json(
      { status: false, message: "Unable to connect to the wallet API." },
      { status: 500 },
    );
  }
}
