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

interface QueryParams {
    siteId: string;
}

export async function GET(request: NextRequest) {
    const searchParams = request.nextUrl.searchParams;
    const siteId = searchParams.get("siteId");
    
    try {
        const site = await prisma.site.findUnique({
            where: {
                id: Number(siteId),
            },
            include: {
                networks: {
                    orderBy: {
                        name: 'asc',
                    },
                },
            },
        });
        
        return NextResponse.json({ site });
    } catch (error) {
        console.error("Error fetching site:", error);
        return NextResponse.json({ error: "Failed to fetch site" }, { status: 500 });
    }
}