Spaces:
Runtime error
Runtime error
File size: 4,848 Bytes
ad79323 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 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];
|