namespace MealPlan.Api.DTOs.Generators;

public class DietUserProfileDto
{
    public decimal HeightCm { get; set; }
    public decimal WeightKg { get; set; }
    public int Age { get; set; }
    public string Sex { get; set; } = "male";
    public string ActivityLevel { get; set; } = "moderate";
    public string Goal { get; set; } = "maintain";
    public string? AllergiesNotes { get; set; }
    public string? DislikedFoods { get; set; }
    public int MealsPerDayMask { get; set; } = 15;
}

public class CreateDietGeneratorSessionDto
{
    public DateOnly? PlanStartDate { get; set; }
    public int PlanDayCount { get; set; } = 7;
    public int CalorieToleranceKcal { get; set; } = 10;
}

public class MacroProposalDto
{
    public int Calories { get; set; }
    public decimal ProteinG { get; set; }
    public decimal FatG { get; set; }
    public decimal CarbsG { get; set; }
    public string? Rationale { get; set; }
}

public class AcceptMacrosDto
{
    public int? Calories { get; set; }
    public decimal? ProteinG { get; set; }
    public decimal? FatG { get; set; }
    public decimal? CarbsG { get; set; }
}

public class DietGeneratorSessionDto
{
    public int Id { get; set; }
    public string Status { get; set; } = string.Empty;
    public MacroProposalDto? ProposedMacros { get; set; }
    public DateOnly? PlanStartDate { get; set; }
    public int PlanDayCount { get; set; }
    public int CalorieToleranceKcal { get; set; }
    public IReadOnlyList<DietGeneratorDraftMealDto> DraftMeals { get; set; } = Array.Empty<DietGeneratorDraftMealDto>();
    public IReadOnlyList<DietGeneratorDaySummaryDto> DaySummaries { get; set; } = Array.Empty<DietGeneratorDaySummaryDto>();
}

public class DietGeneratorDraftMealDto
{
    public int Id { get; set; }
    public DateOnly PlanDate { get; set; }
    public int MealCategory { get; set; }
    public int RecipeId { get; set; }
    public string RecipeName { get; set; } = string.Empty;
    public decimal Portions { get; set; }
    public int? Calories { get; set; }
    public decimal? ProteinG { get; set; }
    public decimal? FatG { get; set; }
    public decimal? CarbsG { get; set; }
    public bool IsLocked { get; set; }
    public int? PrepTimeMinutes { get; set; }
    public IReadOnlyList<DietGeneratorDraftMealIngredientDto> Ingredients { get; set; } =
        Array.Empty<DietGeneratorDraftMealIngredientDto>();
    public IReadOnlyList<DietGeneratorDraftMealStepDto> Steps { get; set; } =
        Array.Empty<DietGeneratorDraftMealStepDto>();
}

public class DietGeneratorDraftMealStepDto
{
    public int Id { get; set; }
    public int StepNumber { get; set; }
    public string Description { get; set; } = string.Empty;
}

public class DietGeneratorDraftMealIngredientDto
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public decimal? AmountGrams { get; set; }
    public string? Unit { get; set; }
    public int SortOrder { get; set; }
    public int? SourceIngredientId { get; set; }
}

public class DietGeneratorDaySummaryDto
{
    public DateOnly PlanDate { get; set; }
    public int TotalCalories { get; set; }
    public int TargetCalories { get; set; }
    public bool WithinTolerance { get; set; }
}

public class RegenerateDietMealDto
{
    public DateOnly PlanDate { get; set; }
    public int MealCategory { get; set; }
}

public class UpdateDraftMealDto
{
    public int? RecipeId { get; set; }
    public decimal? Portions { get; set; }
    public bool? IsLocked { get; set; }
}

public class CommitDietPlanResultDto
{
    public int SessionId { get; set; }
    public DateOnly PlanStartDate { get; set; }
    public DateOnly PlanEndDate { get; set; }
    public int MealsWritten { get; set; }
}

public class RecipeGeneratorConstraintsDto
{
    public string Prompt { get; set; } = string.Empty;
    public int MealCategory { get; set; }
    public int? TargetCalories { get; set; }
    public int CalorieToleranceKcal { get; set; } = 10;
    public int? MaxPrepTimeMinutes { get; set; }
    public string? CuisineStyle { get; set; }
    public string? DietStyle { get; set; }
    public string? Exclusions { get; set; }
}

public class GeneratedIngredientDto
{
    public string Name { get; set; } = string.Empty;
    public decimal? AmountGrams { get; set; }
    public string? Unit { get; set; }
    public int? CatalogItemId { get; set; }
    public string? CatalogName { get; set; }
    public bool IsLinked { get; set; }
}

public class GeneratedStepDto
{
    public int StepNumber { get; set; }
    public string Description { get; set; } = string.Empty;
}

public class GeneratedRecipeDraftDto
{
    public string DraftId { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public int MealCategory { get; set; }
    public int? PrepTimeMinutes { get; set; }
    public int? Calories { get; set; }
    public decimal? Protein { get; set; }
    public decimal? Fat { get; set; }
    public decimal? Carbs { get; set; }
    public IReadOnlyList<GeneratedIngredientDto> Ingredients { get; set; } = Array.Empty<GeneratedIngredientDto>();
    public IReadOnlyList<GeneratedStepDto> Steps { get; set; } = Array.Empty<GeneratedStepDto>();
    public int UnlinkedIngredientCount { get; set; }
}

public class RecipeGeneratorSessionDto
{
    public int Id { get; set; }
    public string Status { get; set; } = string.Empty;
    public RecipeGeneratorConstraintsDto Constraints { get; set; } = new();
    public GeneratedRecipeDraftDto? Draft { get; set; }
    public IReadOnlyList<GeneratedRecipeDraftDto> Drafts { get; set; } = Array.Empty<GeneratedRecipeDraftDto>();
    public int? SavedRecipeId { get; set; }
    public int GenerationVersion { get; set; }
}

public class GenerateRecipesRequestDto
{
    public int Count { get; set; } = 3;
}

public class CommitRecipesRequestDto
{
    public IReadOnlyList<string>? DraftIds { get; set; }
}

public class RegenerateRecipePartDto
{
    public string DraftId { get; set; } = string.Empty;
    public string Mode { get; set; } = "ingredients";
    public string? Instruction { get; set; }
}

public class CommitRecipeResultDto
{
    public int SessionId { get; set; }
    public int RecipeId { get; set; }
    public string RecipeName { get; set; } = string.Empty;
    public string DraftId { get; set; } = string.Empty;
}

public class CommitRecipesResultDto
{
    public int SessionId { get; set; }
    public IReadOnlyList<CommitRecipeResultDto> Saved { get; set; } = Array.Empty<CommitRecipeResultDto>();
}
