import { z } from 'zod'; import { nameSchema } from '@/schemas/common'; type TFunction = (key: string) => string; /** * Contact schema with internationalized error messages * Uses Zod v4's improved error handling and common base schemas */ export const getContactSchema = (t: TFunction) => z.object({ name: nameSchema.min(1, { error: t('validation.contact.name_min') }), role: z.string().optional().describe('Contact role or title'), email: z .string() .email({ error: t('validation.contact.email') }) .or(z.literal('')) .optional() .describe('Email address (can be empty)'), phone: z .string() .regex(/^((\+7|7|8)+([0-9()\-\s]){10,15})?$/, { error: t('validation.contact.phone') }) .or(z.literal('')) .optional() .describe('Phone number (Russian format, can be empty)'), }); /** * Base contact schema for data consistency * Uses Zod v4's composition with common schemas for DRY code */ export const contactSchema = z.object({ name: nameSchema.min(1, { error: 'Name is required.' }), role: z.string().optional().describe('Contact role or title'), email: z .string() .email({ error: 'Please enter a valid email address.' }) .or(z.literal('')) .optional() .describe('Email address (can be empty)'), phone: z .string() .regex(/^((\+7|7|8)+([0-9()\-\s]){10,15})?$/, { error: 'Please enter a valid phone number.' }) .or(z.literal('')) .optional() .describe('Phone number (Russian format, can be empty)'), });