import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { challengeService } from "@/services/challenges/challenge.service";

export async function GET() {
  try {
    const session = await auth();

    if (!session?.user?.id) {
      return NextResponse.json({ count: 0 });
    }

    const count = await challengeService.getActiveChallengesCount(
      session.user.id
    );

    return NextResponse.json({ count });
  } catch (error) {
    console.error("Error fetching active challenges count:", error);
    return NextResponse.json({ count: 0 });
  }
}

