export interface DietUserProfile {
  heightCm: number;
  weightKg: number;
  age: number;
  sex: 'male' | 'female';
  activityLevel: 'sedentary' | 'light' | 'moderate' | 'active' | 'very_active';
  goal: 'lose_weight' | 'maintain' | 'gain_muscle' | 'recomp';
  allergiesNotes?: string | null;
  dislikedFoods?: string | null;
  mealsPerDayMask: number;
}

export interface MacroProposal {
  calories: number;
  proteinG: number;
  fatG: number;
  carbsG: number;
  rationale?: string | null;
}

export interface DietGeneratorDraftMealIngredient {
  id: number;
  name: string;
  amountGrams?: number | null;
  unit?: string | null;
  sortOrder: number;
  sourceIngredientId?: number | null;
}

export interface DietGeneratorDraftMealStep {
  id: number;
  stepNumber: number;
  description: string;
}

export interface DietGeneratorDraftMeal {
  id: number;
  planDate: string;
  mealCategory: number;
  recipeId: number;
  recipeName: string;
  portions: number;
  calories?: number | null;
  proteinG?: number | null;
  fatG?: number | null;
  carbsG?: number | null;
  isLocked: boolean;
  prepTimeMinutes?: number | null;
  ingredients: DietGeneratorDraftMealIngredient[];
  steps: DietGeneratorDraftMealStep[];
}

export interface DietGeneratorDaySummary {
  planDate: string;
  totalCalories: number;
  targetCalories: number;
  withinTolerance: boolean;
}

export interface DietGeneratorSession {
  id: number;
  status: string;
  proposedMacros?: MacroProposal | null;
  planStartDate?: string | null;
  planDayCount: number;
  calorieToleranceKcal: number;
  draftMeals: DietGeneratorDraftMeal[];
  daySummaries: DietGeneratorDaySummary[];
}

export interface CommitDietPlanResult {
  sessionId: number;
  planStartDate: string;
  planEndDate: string;
  mealsWritten: number;
}

export interface RecipeGeneratorConstraints {
  prompt: string;
  mealCategory: number;
  targetCalories?: number | null;
  calorieToleranceKcal?: number;
  maxPrepTimeMinutes?: number | null;
  cuisineStyle?: string | null;
  dietStyle?: string | null;
  exclusions?: string | null;
}

export interface GeneratedIngredient {
  name: string;
  amountGrams?: number | null;
  unit?: string | null;
  catalogItemId?: number | null;
  catalogName?: string | null;
  isLinked: boolean;
}

export interface GeneratedStep {
  stepNumber: number;
  description: string;
}

export interface GeneratedRecipeDraft {
  draftId: string;
  name: string;
  mealCategory: number;
  prepTimeMinutes?: number | null;
  calories?: number | null;
  protein?: number | null;
  fat?: number | null;
  carbs?: number | null;
  ingredients: GeneratedIngredient[];
  steps: GeneratedStep[];
  unlinkedIngredientCount: number;
}

export interface RecipeGeneratorSession {
  id: number;
  status: string;
  constraints: RecipeGeneratorConstraints;
  draft?: GeneratedRecipeDraft | null;
  drafts: GeneratedRecipeDraft[];
  savedRecipeId?: number | null;
  generationVersion: number;
}

export interface CommitRecipeResult {
  sessionId: number;
  recipeId: number;
  recipeName: string;
  draftId: string;
}

export interface CommitRecipesResult {
  sessionId: number;
  saved: CommitRecipeResult[];
}

export const DEFAULT_DIET_PROFILE: DietUserProfile = {
  heightCm: 175,
  weightKg: 75,
  age: 30,
  sex: 'male',
  activityLevel: 'moderate',
  goal: 'maintain',
  mealsPerDayMask: 15,
  allergiesNotes: '',
  dislikedFoods: '',
};
