import { z } from "zod" import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator" const quantitySchemaWithoutRefine = z.object({ quantityWithPoints: z.number().nullable(), quantityWithCard: z.number().nullable(), }) export const ancillaryError = { TERMS_NOT_ACCEPTED: "TERMS_NOT_ACCEPTED", MIN_QUANTITY_NOT_REACHED: "MIN_QUANTITY_NOT_REACHED", } as const export const quantitySchema = z .object({}) .merge(quantitySchemaWithoutRefine) .refine( (data) => (data.quantityWithPoints ?? 0) > 0 || (data.quantityWithCard ?? 0) > 0, { message: ancillaryError.MIN_QUANTITY_NOT_REACHED, path: ["quantityWithCard"], } ) export const ancillaryFormSchema = z .object({ deliveryTime: z.string(), optionalText: z.string(), termsAndConditions: z .boolean() .refine((value) => value === true, ancillaryError.TERMS_NOT_ACCEPTED), optInEmail: z.boolean(), paymentMethod: nullableStringValidator, }) .merge(quantitySchemaWithoutRefine) .refine( (data) => (data.quantityWithPoints ?? 0) > 0 || (data.quantityWithCard ?? 0) > 0, { message: ancillaryError.MIN_QUANTITY_NOT_REACHED, path: ["quantityWithCard"], } ) export type AncillaryQuantityFormData = z.output< typeof quantitySchemaWithoutRefine > export type AncillaryFormData = z.output