import { z } from 'zod';

const uuidSchema = z.uuid('Must be a valid UUID');

export const toggleWishlistBodySchema = z.object({
  dealId: uuidSchema,
  notify: z.boolean().optional(),
});
export type ToggleWishlistBody = z.infer<typeof toggleWishlistBodySchema>;

export const toggleWishlistResponseSchema = z.object({
  ok: z.literal(true),
  saved: z.boolean(),
  notify: z.boolean(),
});
export type ToggleWishlistResponse = z.infer<typeof toggleWishlistResponseSchema>;

export const setWishlistNotifyBodySchema = z.object({
  dealId: uuidSchema,
  notify: z.boolean(),
});
export type SetWishlistNotifyBody = z.infer<typeof setWishlistNotifyBodySchema>;

export const setWishlistNotifyAllBodySchema = z.object({
  notify: z.boolean(),
});
export type SetWishlistNotifyAllBody = z.infer<typeof setWishlistNotifyAllBodySchema>;

export const wishlistItemSchema = z.object({
  id: uuidSchema,
  dealId: uuidSchema,
  notify: z.boolean(),
  createdAt: z.iso.datetime(),
  deal: z.object({
    id: uuidSchema,
    title: z.string(),
    discountedPrice: z.string(),
    originalPrice: z.string(),
    discountPercent: z.number(),
    dealState: z.string(),
    windowEnd: z.iso.datetime().nullable(),
    vendorId: z.string(),
    vendorName: z.string(),
  }),
});
export type WishlistItem = z.infer<typeof wishlistItemSchema>;

export const listWishlistResponseSchema = z.object({
  ok: z.literal(true),
  items: z.array(wishlistItemSchema),
});
export type ListWishlistResponse = z.infer<typeof listWishlistResponseSchema>;

export const mergeWishlistBodySchema = z.object({
  dealIds: z.array(uuidSchema).min(1).max(200),
});
export type MergeWishlistBody = z.infer<typeof mergeWishlistBodySchema>;
