import { NextRequest, NextResponse } from "next/server";
import { adminUnauthorizedResponse, isAdminRequestAuthorized } from "@/lib/admin-auth";
import { getTreasurySnapshot } from "@/lib/treasury-snapshot";

export async function GET(request: NextRequest) {
  if (!isAdminRequestAuthorized(request)) {
    return adminUnauthorizedResponse();
  }

  try {
    return NextResponse.json(await getTreasurySnapshot());

  } catch (error: unknown) {
    console.error("[Treasury Stats Error]", error);
    return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
  }
}
