import { eq, sql } from "drizzle-orm"
import { db } from "@/lib/db/client"
import { departments, people, positions } from "@/lib/db/schema"

const rows = await db
  .select({ title: positions.title, dept: departments.name })
  .from(positions)
  .innerJoin(departments, eq(departments.id, positions.departmentId))
  .where(sql`not exists (
    select 1 from people p
    where p.position_id = ${positions.id} and p.archived_at is null
  )`)
console.log("postes sans titulaire actif :", rows)

const [tout] = await db
  .select({ n: sql<number>`count(*)::int` })
  .from(positions)
  .where(sql`not exists (select 1 from people p where p.position_id = ${positions.id})`)
console.log("postes sans aucun titulaire, meme parti :", tout?.n)
process.exit(0)
