import { z } from "zod"; import { US_STATE_CODES } from "@/data/areas"; import { LOCATION_STATUS_OPTIONS } from "@/domain/locations/types/location"; export const locationContactSchema = z.object({ id: z.number().int().positive().optional(), name: z .string() .trim() .min(1, "Contact person is required") .max(100, "Contact person cannot exceed 100 characters"), phone: z.string().trim().min(1, "Phone is required").max(20, "Phone cannot exceed 20 characters"), }); export const locationSchema = z.object({ name: z.string().min(1, "Name is required"), accountId: z.string().optional(), address: z.string().min(1, "Address is required"), city: z.string().min(1, "City is required"), state: z .union([z.enum(US_STATE_CODES), z.literal("")]) .refine((state): boolean => state !== "", { message: "State is required" }), zipCode: z.string().min(1, "Zip code is required"), contacts: z.array(locationContactSchema).min(1, "At least one contact is required"), contactEmail: z.string().min(1, "Contact email is required").email("Invalid email address"), status: z.enum(LOCATION_STATUS_OPTIONS, { message: "Status is required" }), }); export type LocationFormValues = z.infer; export type LocationContactFormValues = z.infer; export const locationDefaultValues: LocationFormValues = { name: "", accountId: "", address: "", city: "", state: "", zipCode: "", contacts: [{ name: "", phone: "" }], contactEmail: "", status: "Active", };