import type { IngredientView, UnitView } from "./reference.js";

/**
 * One aggregated ingredient line in a shopping list — every
 * `RecipeIngredient` line of every recipe planned for the week, summed
 * across recipes/planning items. `quantity` already accounts for each
 * planning item's own portion count (`RecipeIngredient.quantity ×
 * PlanningItem.portions / Recipe.portions`, see the API's
 * `shopping-list.service.ts`), so this is the real amount to buy, not the
 * recipe's as-written quantity.
 *
 * Quantities are only ever summed when both `ingredient` **and** `unit`
 * match exactly — `UnitView.toBaseFactor` exists as groundwork for a future
 * cross-unit conversion (e.g. summing "500g" + "0.5kg" into "1kg"), not yet
 * built (see that field's own doc comment), so the same ingredient
 * requested in two different units surfaces as two separate lines rather
 * than silently guessing a conversion.
 */
export interface ShoppingListItemView {
  ingredient: IngredientView;
  quantity: number;
  unit: UnitView;
}

/**
 * A household's shopping list for the week starting `startDate`, as
 * returned by `GET /shopping-list`. Unlike `PlanningView`, this is
 * **never** `null` — a caller with no household, or whose household has no
 * planning for that week yet, both degrade to an empty `items` array
 * (nothing to shop for is a normal state to render directly, not a
 * separate "no list" case to branch on).
 */
export interface ShoppingListView {
  startDate: string;
  finishDate: string;
  items: ShoppingListItemView[];
}
