import { NextResponse } from 'next/server';

const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000';

export const dynamic = 'force-dynamic';
export const revalidate = 30;

export async function GET(): Promise<NextResponse<{ count: number }>> {
  try {
    const res = await fetch(`${BACKEND_URL}/api/stats/parlays-graded`, {
      next: { revalidate: 30 },
      headers: { Accept: 'application/json' },
    });
    if (!res.ok) return NextResponse.json({ count: 0 });
    const data = (await res.json()) as { count?: number };
    return NextResponse.json({ count: Number(data.count || 0) });
  } catch {
    return NextResponse.json({ count: 0 });
  }
}
