import { z } from 'zod';

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

export const toggleFavoriteBodySchema = z.object({
  vendorId: uuidSchema,
  notify: z.boolean().optional(),
});
export type ToggleFavoriteBody = z.infer<typeof toggleFavoriteBodySchema>;

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

export const setFavoriteNotifyBodySchema = z.object({
  vendorId: uuidSchema,
  notify: z.boolean(),
});
export type SetFavoriteNotifyBody = z.infer<typeof setFavoriteNotifyBodySchema>;

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

export const favoriteVendorItemSchema = z.object({
  id: uuidSchema,
  vendorId: uuidSchema,
  notify: z.boolean(),
  createdAt: z.iso.datetime(),
  vendor: z.object({
    id: uuidSchema,
    displayName: z.string(),
    logoUrl: z.string().nullable(),
    category: z.string().nullable(),
  }),
});
export type FavoriteVendorItem = z.infer<typeof favoriteVendorItemSchema>;

export const listFavoritesResponseSchema = z.object({
  ok: z.literal(true),
  items: z.array(favoriteVendorItemSchema),
});
export type ListFavoritesResponse = z.infer<typeof listFavoritesResponseSchema>;
