import type { NutritionInfo } from './product.js';
import type { NutritionWarning } from '../enums/recipe.enums.js';

/** Units stored in the database — always metric or discrete. */
export type RecipeUnit = 'g' | 'ml' | 'piece' | 'slice';

/** Accepted at recipe input / import only; converted to RecipeUnit before persistence. */
export type ImperialUnit = 'oz' | 'lb' | 'cup' | 'tbsp' | 'tsp' | 'fl_oz';

export interface RecipeIngredient {
  productId: string; // Reference to Product
  productName: string; // Denormalized for display
  quantity: number; // stored in metric (g | ml) or as a discrete count
  unit: RecipeUnit; // metric/discrete only after normalization
  originalQuantity?: number; // preserved from import (e.g. 1)
  originalUnit?: ImperialUnit | RecipeUnit; // preserved from import (e.g. 'cup')
  preparation?: string; // e.g., 'diced', 'minced', 'melted'
  isOptional: boolean;
  nutritionContribution: NutritionInfo; // per-ingredient computed nutrition
}

export interface RecipeStep {
  order: number;
  instruction: string;
  duration?: number; // minutes
  tip?: string;
}

export interface RecipeSource {
  type: 'manual' | 'url' | 'llm_import' | 'text_import';
  url?: string;
  importedAt?: Date;
}

export interface Recipe {
  id: string;
  householdId: string;
  name: string;
  description?: string;
  servings: number;
  prepTime?: number; // minutes
  cookTime?: number; // minutes
  totalTime?: number; // minutes (computed or manual)
  ingredients: RecipeIngredient[];
  steps: RecipeStep[];
  tags: string[];
  cuisine?: string;
  imageUrl?: string;
  source?: RecipeSource;
  totalNutrition: NutritionInfo; // denormalized, computed on save
  perServingNutrition: NutritionInfo; // denormalized, computed on save
  warnings: NutritionWarning[]; // computed on save
  isFavorite: boolean;
  createdBy: string;
  createdAt: Date;
  updatedAt: Date;
  deletedAt?: Date;
}
