import { z } from "zod" import { supportedLanguageCodes } from "@/lib/i18n/config" const optionalText = z.preprocess( (value) => { if (typeof value !== "string") return null const trimmed = value.trim() return trimmed.length > 0 ? trimmed : null }, z.string().nullable(), ) const optionalEmail = z.preprocess( (value) => { if (typeof value !== "string") return null const trimmed = value.trim() return trimmed.length > 0 ? trimmed : null }, z.email().nullable(), ) export const createInvitationSchema = z .object({ displayName: z.string().trim().min(1, "Display name is required"), language: z.enum(supportedLanguageCodes, { error: "Select a supported language", }), contactEmail: optionalEmail.optional().default(null), contactPhone: optionalText.optional().default(null), maxPartySize: z.coerce .number() .int("Party size must be a whole number") .min(1, "Party size must be at least 1"), allowMemberEdits: z.coerce.boolean().default(false), notes: optionalText.optional().default(null), members: z .array(z.string().trim().min(1)) .min(1, "Add at least one invitation member"), }) .refine((value) => value.members.length <= value.maxPartySize, { message: "Members cannot exceed max party size", path: ["members"], }) export const deleteInvitationSchema = z.object({ invitationId: z.uuid(), }) export const updateSaveTheDateSentSchema = z.object({ invitationId: z.uuid(), sent: z.boolean(), }) export const updateInvitationLanguageSchema = z.object({ invitationId: z.uuid(), language: z.enum(supportedLanguageCodes, { error: "Select a supported language", }), }) export type CreateInvitationInput = z.infer export type DeleteInvitationInput = z.infer export type UpdateSaveTheDateSentInput = z.infer export type UpdateInvitationLanguageInput = z.infer