import { z } from "zod";

export const shoppingItemSchema = z.object({
  id: z.string(),
  householdId: z.string(),
  label: z.string(),
  quantity: z.string().nullable(),
  addedBy: z.string(),
  checkedBy: z.string().nullable(),
  checkedAt: z.string().nullable(),
  sortOrder: z.number(),
  createdAt: z.string(),
});

export type ShoppingItem = z.infer<typeof shoppingItemSchema>;

export const addShoppingItemSchema = z.object({
  label: z.string().min(1),
  quantity: z.string().optional(),
});

export type AddShoppingItemInput = z.infer<typeof addShoppingItemSchema>;

// WebSocket event types sent from server → client
export type ShoppingServerEvent =
  | { type: "item:added"; item: ShoppingItem }
  | { type: "item:checked"; itemId: string; checkedBy: string; checkedAt: string }
  | { type: "item:unchecked"; itemId: string }
  | { type: "item:deleted"; itemId: string }
  | { type: "item:cleared" }
  | { type: "sync"; items: ShoppingItem[] };

// WebSocket command types sent from client → server
export type ShoppingClientCommand =
  | { type: "item:add"; label: string; quantity?: string }
  | { type: "item:check"; itemId: string }
  | { type: "item:uncheck"; itemId: string }
  | { type: "item:delete"; itemId: string }
  | { type: "item:clear" };
