import { z } from "zod"; import { calendarViewValues, caseStatusValues, caseTypeValues, sessionDatePresetValues, } from "@/lib/constants"; const caseBaseFields = { caseName: z .string() .trim() .min(2, "اسم القضية لازم يكون حرفين على الأقل.") .max(160, "اسم القضية طويل زيادة عن اللزوم."), type: z.enum(caseTypeValues, { error: "اختار نوع القضية.", }), subType: z .string() .trim() .max(120, "النوع الفرعي طويل زيادة عن اللزوم.") .optional() .or(z.literal("")), opponentFullName: z .string() .trim() .min(3, "اسم الخصم لازم يكون 3 حروف على الأقل.") .max(180, "اسم الخصم طويل زيادة عن اللزوم."), description: z .string() .trim() .max(1000, "الوصف طويل زيادة عن اللزوم.") .optional() .or(z.literal("")), }; export const caseCreateSchema = z.object(caseBaseFields); export const caseUpdateSchema = z.discriminatedUnion("action", [ z.object({ action: z.literal("update"), ...caseBaseFields, }), z.object({ action: z.literal("close"), }), z.object({ action: z.literal("reopen"), }), ]); export const caseListQuerySchema = z.object({ caseSearch: z.string().trim().max(100).optional().catch(undefined), caseType: z.enum(caseTypeValues).optional().catch(undefined), tab: z .enum(["info", "cases", "sessions", "archive"]) .optional() .catch(undefined), }); export const caseFileListQuerySchema = z.object({ fileSearch: z.string().trim().max(100).optional().catch(undefined), fileId: z.string().trim().optional().catch(undefined), sessionPreset: z .enum(sessionDatePresetValues) .optional() .catch(undefined) .default("all"), sessionId: z.string().trim().optional().catch(undefined), tab: z.enum(["info", "files", "sessions", "chat"]).optional().catch(undefined), }); export const caseFileMetadataSchema = z.object({ displayName: z .string() .trim() .min(2, "اسم الملف لازم يكون حرفين على الأقل.") .max(160, "اسم الملف طويل زيادة عن اللزوم."), description: z .string() .trim() .max(500, "وصف الملف طويل زيادة عن اللزوم.") .optional() .or(z.literal("")), }); export const courtSessionCreateSchema = z.object({ governorate: z .string() .trim() .min(2, "اختار المحافظة.") .max(120, "اسم المحافظة غير صالح."), courtName: z .string() .trim() .min(2, "اختار المحكمة.") .max(200, "اسم المحكمة غير صالح."), locationDetails: z .string() .trim() .max(250, "تفاصيل المكان طويلة زيادة عن اللزوم.") .optional() .or(z.literal("")), scheduledAt: z .string() .trim() .min(1, "حدد التاريخ والوقت."), }); export const courtSessionUpdateSchema = z.object({ scheduledAt: z .string() .trim() .min(1, "حدد التاريخ والوقت الجديد."), }); export const courtSessionListQuerySchema = z.object({ sessionPreset: z .enum(sessionDatePresetValues) .optional() .catch(undefined) .default("all"), sessionId: z.string().trim().optional().catch(undefined), tab: z.enum(["info", "cases", "sessions", "archive"]).optional().catch(undefined), }); export const courtsGovernorateQuerySchema = z.object({ governorate: z.string().trim().min(2).max(120), }); export const calendarSessionsQuerySchema = z.object({ view: z.enum(calendarViewValues).optional().catch(undefined).default("week"), anchor: z.string().trim().optional().catch(undefined), }); export const caseChatQuestionSchema = z.object({ question: z .string() .trim() .min(2, "اكتب سؤالك الأول.") .max(4000, "السؤال طويل زيادة عن اللزوم."), }); export type CaseCreateInput = z.infer; export type CaseUpdateInput = z.infer; export type CaseListQueryInput = z.infer; export type CaseFileListQueryInput = z.infer; export type CaseFileMetadataInput = z.infer; export type CourtSessionCreateInput = z.infer; export type CourtSessionUpdateInput = z.infer; export type CourtSessionListQueryInput = z.infer; export type CalendarSessionsQueryInput = z.infer; export type CaseChatQuestionInput = z.infer; export type CaseStatusInput = (typeof caseStatusValues)[number];