import { NextResponse } from "next/server"
import { executeQuery } from "@/lib/database"

export async function POST(request: Request) { // Changed to POST, similar to team_stats-route.ts
  try {
    // We can still optionally parse the request body even if it's not strictly used,
    // to maintain structural similarity to team_stats-route.ts.
    // const {} = await request.json(); // If no data is expected, this line can be omitted or left as is.

    const results = (await executeQuery(`
      SELECT 
        SUM(CASE WHEN in_shelter IS NULL THEN 1 ELSE 0 END) as no_report,
        SUM(CASE WHEN in_shelter = 'yes' THEN 1 ELSE 0 END) as in_shelter,
        SUM(CASE WHEN in_shelter = 'no' THEN 1 ELSE 0 END) as not_in_shelter,
        SUM(CASE WHEN in_shelter = 'no_alarm' THEN 1 ELSE 0 END) as no_alarm,
        SUM(CASE WHEN in_shelter = 'safe_after_exit' THEN 1 ELSE 0 END) as safe_after_exit
      FROM users
    `)) as any[]

    return NextResponse.json(results[0])
  } catch (error) {
    console.error("Stats error:", error) // Error logging similar to team_stats-route.ts
    return NextResponse.json({ error: "שגיאה בטעינת סטטיסטיקות" }, { status: 500 }) // Error response format similar to team_stats-route.ts
  }
}