import { NextResponse } from "next/server";
import { getSessionUser } from "@/lib/auth/get-session-user";
import { buildAutoPostMonitorSnapshot } from "@/lib/scheduling/auto-post-monitor";

export async function GET(request: Request) {
  const user = await getSessionUser();
  if (!user) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const { searchParams } = new URL(request.url);
  const projectId = searchParams.get("projectId") ?? undefined;

  const monitor = await buildAutoPostMonitorSnapshot(user.id, projectId);
  return NextResponse.json(monitor);
}
