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

  export default createCrudRouter({
    table: "deadline",
    entityType: "deadline",
    auditPrefix: "DEADLINE",
    listSql: `SELECT d.id, d.case_id, c.case_number, d.title, d.deadline_type, d.due_date, d.status, d.remind_days_before, d.created_at FROM deadline d LEFT JOIN br_case c ON c.id = d.case_id WHERE d.deleted_at IS NULL ORDER BY d.due_date`,
    detailSql: `SELECT * FROM deadline WHERE id = $1 AND deleted_at IS NULL`,
    deleteSql: `UPDATE deadline SET deleted_at = NOW() WHERE id = $1 RETURNING *`,
    writeRoles: ['admin', 'chair', 'secretary', 'member'],
    writePermission: 'deadlines.write',
    fields: [
      { name: 'case_id', schema: z.number().int().nullable().optional() },
{ name: 'title', schema: z.string().min(2).max(255) },
{ name: 'deadline_type', schema: z.string().min(2).max(50) },
{ name: 'due_date', schema: z.string().datetime() },
{ name: 'status', schema: z.string().min(2).max(30).default('offen') },
{ name: 'remind_days_before', schema: z.number().int().min(0).max(90).default(2) },
{ name: 'created_by', schema: z.number().int().optional().nullable() },
{ name: 'updated_by', schema: z.number().int().optional().nullable() }
    ]
  });
