import { z } from 'zod'; import { SCHEDULING_TYPE } from '../../constants/host.constant'; const WeekdayEnum = z.enum([ 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', ]); export const scheduleActivity = z.object({ activityXid: z.number(), listNow: z.boolean(), scheduleType: z.enum([ SCHEDULING_TYPE.ONCE, SCHEDULING_TYPE.WEEKLY, SCHEDULING_TYPE.MONTHLY, SCHEDULING_TYPE.CUSTOM, ]), dateRange: z.object({ startDate: z.string(), endDate: z.string().nullable().optional(), }), rules: z.object({ weekdays: z.array(WeekdayEnum).optional(), monthDates: z.array(z.number()).optional(), customDates: z.array(z.string()).optional(), }), venues: z.array( z.object({ venueXid: z.number(), slots: z.array( z.object({ startTime: z.string(), endTime: z.string(), weekDay: WeekdayEnum.nullable().optional(), dayOfMonth: z.number().nullable().optional(), occurrenceDate: z.string().nullable().optional(), maxCapacity: z.number(), }) ).optional().default([]), }) ), earlyCheckInMins: z.number().optional(), bookingCutOffMins: z.number().optional(), isLateCheckingAllowed: z.boolean().optional(), isInstantBooking: z.boolean().optional(), }) .superRefine((data, ctx) => { if (data.scheduleType === 'WEEKLY' && !data.rules.weekdays?.length) { ctx.addIssue({ path: ['rules', 'weekdays'], message: 'Weekdays required for WEEKLY schedule', code: 'custom' }); } if (data.scheduleType === 'MONTHLY' && !data.rules.monthDates?.length) { ctx.addIssue({ path: ['rules', 'monthDates'], message: 'Month dates required for MONTHLY schedule', code: 'custom' }); } if ( (data.scheduleType === 'CUSTOM' || data.scheduleType === 'ONCE') && !data.rules.customDates?.length ) { ctx.addIssue({ path: ['rules', 'customDates'], message: 'Custom dates required', code: 'custom' }); } }); export type ScheduleActivityDTO = z.infer;