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

export async function GET() {
  try {
    const users = (await safeQuery(`
      SELECT 
        national_id,
        name,
        in_shelter,
        last_updated,
        is_admin,
        must_change_password,
        field,
        department,
        team,
        lock_status
      FROM users
      ORDER BY field, department, team, name
    `)) as any[]

    return NextResponse.json(users)
  } catch (error) {
    console.error("Get users error:", error)
    return NextResponse.json({ error: "שגיאה בטעינת משתמשים" }, { status: 500 })
  }
}