import { z } from "zod";
import { MEAL_TYPES } from "@app/shared-types";
import { dateStringSchema, uuidSchema } from "./common.js";

/** Veckoplan (spec §25). */
export const generateWeekPlanInputSchema = z.object({
  weekStartDate: dateStringSchema,
  daysToPlann: z.number().int().min(1).max(14).optional(),
  mealTypes: z.array(z.enum(MEAL_TYPES)).min(1).default(["dinner"]),
  portionsPerMeal: z.number().int().min(1).max(20).optional(),
  budgetMinorTotal: z.number().int().min(0).max(5_000_000).optional(),
  /** T.ex. "Sju middagar för fyra personer under 1 000 kr" (spec §26). */
  noteSv: z.string().max(300).optional(),
  preferLeftoversFirst: z.boolean().default(true),
  varietyLevel: z.enum(["low", "medium", "high"]).default("medium"),
});
export type GenerateWeekPlanInput = z.infer<typeof generateWeekPlanInputSchema>;

export const updatePlanEntryInputSchema = z.object({
  date: dateStringSchema.optional(),
  mealType: z.enum(MEAL_TYPES).optional(),
  recipeId: uuidSchema.nullable().optional(),
  mealBoxId: uuidSchema.nullable().optional(),
  portions: z.number().int().min(1).max(24).optional(),
  status: z.enum(["planned", "cooked", "skipped", "moved"]).optional(),
});
export type UpdatePlanEntryInput = z.infer<typeof updatePlanEntryInputSchema>;

export const weekPlanQuerySchema = z.object({
  weekStartDate: dateStringSchema.optional(),
});
