import { NextRequest, NextResponse } from "next/server";
import { restApiFetch } from "@/utils/bagisto";
import { isBagistoError } from "@/utils/type-guards";
import { getAuthToken } from "@/utils/helper";
// import type { GiftListBody,FetchWrap  } from '@/types/api/gift/lists';
export async function GET(req: NextRequest) {
    try {
        const guestToken = getAuthToken(req);
        // 从查询参数取 page，默认 1
        const id = req.nextUrl.searchParams.get("id") || "1";
        const response = await restApiFetch<any>({
            api: `/shop/customer-address-gets?id=${id}`,
            method:'GET',
            cache:'no-store',
            guestToken,
        });
        return NextResponse.json({
            status: response.status,
            data: response.body,
        });
    } catch (error) {
        if (isBagistoError(error)) {
            return NextResponse.json(
                {
                    data: null,
                    error: error.cause ?? error,
                },
                { status: 200 }
            );
        }

        return NextResponse.json(
            {
                message: "Network error",
                error: error instanceof Error ? error.message : error,
            },
            { status: 500 }
        );
    }
}
