import { NextResponse } from "next/server";
import axios from "axios";

export async function GET() {
    try {
        const res = await axios.post("https://gateway.isolarcloud.com.hk/openapi/platform/queryPowerStationList", {
            "page": 1,
            "size": 10,
            "appkey": `${process.env.SUNGROW_APP_KEY}`
        } ,{
            headers: {
                "Authorization": `Bearer ${process.env.SUNGROW_ACCESS_TOKEN}`,
                "x-access-key": `${process.env.SUNGROW_SECRET_KEY}`
            }
        })
        // console.log("res", res.data)
        return NextResponse.json(res.data.result_data.pageList)
    } catch (error) {
        console.error("API fetch error:", error);
        return NextResponse.json({ error: "Failed to fetch inverters" }, { status: 500 });
    }
}
