  import { z } from "zod";
  import { createCrudRouter } from "../crudFactory.js";

  export default createCrudRouter({
    table: "app_user",
    entityType: "user",
    auditPrefix: "USER",
    listSql: `SELECT id, full_name, email, role, committee_id, is_active, two_factor_enabled, security_classification, force_password_reset, created_at FROM app_user ORDER BY full_name`,
    detailSql: `SELECT id, full_name, email, role, committee_id, is_active, two_factor_enabled, security_classification, force_password_reset, last_login_at, created_at FROM app_user WHERE id = $1`,
    deleteSql: `UPDATE app_user SET is_active = FALSE WHERE id = $1 RETURNING id, full_name, email, role, committee_id, is_active`,
    writeRoles: ['admin'],
    writePermission: 'system.users',
    fields: [
      { name: 'full_name', schema: z.string().min(2).max(120) },
{ name: 'email', schema: z.string().email() },
{ name: 'role', schema: z.enum(['admin','chair','member','secretary','advisor']) },
{ name: 'committee_id', schema: z.number().int().nullable().optional() },
{ name: 'is_active', schema: z.boolean().optional().default(true) },
{ name: 'security_classification', schema: z.string().max(30).optional().default('standard') },
{ name: 'force_password_reset', schema: z.boolean().optional().default(false) }
    ]
  });
