Spaces:
Runtime error
Runtime error
| 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<typeof caseCreateSchema>; | |
| export type CaseUpdateInput = z.infer<typeof caseUpdateSchema>; | |
| export type CaseListQueryInput = z.infer<typeof caseListQuerySchema>; | |
| export type CaseFileListQueryInput = z.infer<typeof caseFileListQuerySchema>; | |
| export type CaseFileMetadataInput = z.infer<typeof caseFileMetadataSchema>; | |
| export type CourtSessionCreateInput = z.infer<typeof courtSessionCreateSchema>; | |
| export type CourtSessionUpdateInput = z.infer<typeof courtSessionUpdateSchema>; | |
| export type CourtSessionListQueryInput = z.infer<typeof courtSessionListQuerySchema>; | |
| export type CalendarSessionsQueryInput = z.infer<typeof calendarSessionsQuerySchema>; | |
| export type CaseChatQuestionInput = z.infer<typeof caseChatQuestionSchema>; | |
| export type CaseStatusInput = (typeof caseStatusValues)[number]; | |