import { z } from 'zod'; import { SlideContentSchema } from './slide-content.schema'; import { SLIDE_CONTENT_TYPE, SLIDE_LAYOUT } from '../../constants'; import { SlideIconSlotSchema } from './slide-icon-slot.schema'; import { SlideImageSlotSchema } from './slide-image-slot.schema'; import { SlideContentUserEditSchema } from './slide-content-edit.schema'; export const SlideSchema = z.object({ uuid: z.string().uuid(), order: z.number(), contentTypeId: z.nativeEnum(SLIDE_CONTENT_TYPE), layoutId: z.nativeEnum(SLIDE_LAYOUT), content: SlideContentSchema, presentationId: z.string(), iconSlots: z.array(SlideIconSlotSchema), imageSlots: z.array(SlideImageSlotSchema), createdAt: z.date(), updatedAt: z.date(), }); export type Slide = z.infer; export const SlideUpdateSchema = SlideSchema.pick({ layoutId: true, }) .extend({ content: SlideContentUserEditSchema, }) .partial(); export type SlideUpdate = z.infer; export const SlideBulkUpdateSchema = SlideSchema.pick({ order: true, contentTypeId: true, layoutId: true, presentationId: true, }) .extend({ uuid: z.string().uuid().optional(), content: SlideContentUserEditSchema, }) .array() .min(1, 'Must include at least one slide') .refine( (arr) => { const orders = arr.map((s) => s.order); const unique = new Set(orders); if (unique.size !== orders.length) return false; const sorted = [...orders].sort((a, b) => a - b); return sorted.every((val, idx) => val === idx); }, { message: 'Slide orders must be unique and sequential starting at 0', path: ['order'], }, ) .refine( (arr) => { const [firstId, ...rest] = arr.map((s) => s.presentationId); return rest.every((id) => id === firstId); }, { message: 'All slides must belong to the same presentation', path: ['presentationId'], }, ); export type SlideBulkUpdate = z.infer;