import { z } from 'zod'; import { SLIDE_CONTENT_TYPE } from '../../constants'; export const SlideOutlineSchema = z.object({ uuid: z.string(), order: z.number(), title: z.string().max(80), body: z.string().max(500), contentTypeId: z.nativeEnum(SLIDE_CONTENT_TYPE), presentationId: z.string(), createdAt: z.date(), updatedAt: z.date(), }); export type SlideOutline = z.infer; export const SlideOutlineUpdateSchema = SlideOutlineSchema.pick({ title: true, body: true, contentTypeId: true, }).partial(); export type SlideOutlineUpdate = z.infer; export const SlideOutlineBulkUpdateSchema = SlideOutlineSchema.pick({ order: true, title: true, body: true, contentTypeId: true, presentationId: true, }) .extend({ uuid: z.string().uuid().optional(), }) .array() .min(1, 'Must include at least one slide outline') .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 slide outlines must belong to the same presentation', path: ['presentationId'], }, ); export type SlideOutlineBulkUpdate = z.infer;