feat(planning): implement meal plan prediction engine

Introduce WeeklyMealPredictor and related data models to suggest meals, add prediction state management to the ViewModel, and update the UI to support meal planning automation.
This commit is contained in:
bleackstorm committed 2026-11-22 13:57:39 +01:00
1 parent 8e794e6da7
commit a2f59f15d4
13 files changed
+2247 -17

No files matched your search

@@ -17,6 +17,22 @@ enum class StorageLocation(val displayName: String) {
it.displayName.equals(trimmed, ignoreCase = true)
} ?: PANTRY
}
fun defaultForCategory(category: FoodCategory): StorageLocation {
return when (category) {
FoodCategory.PROTEIN,
FoodCategory.VEGETABLE,
FoodCategory.FRUIT,
FoodCategory.CHEESE,
FoodCategory.DAIRY -> FRIDGE
FoodCategory.STARCH,
FoodCategory.BREAD,
FoodCategory.NUTS,
FoodCategory.FAT_SEASONING,
FoodCategory.PLEASURE,
FoodCategory.OTHER -> PANTRY
}
}
}
}
@@ -135,3 +151,56 @@ sealed interface ReceiptScanUiState {
data class Preview(val items: List<ScannedReceiptItem>) : ReceiptScanUiState
data class Error(val message: String) : ReceiptScanUiState
}
enum class PredictionMealScope(
val displayName: String,
val mealTypes: List<MealType>
) {
MAIN_MEALS("Déjeuner & Dîner", listOf(MealType.LUNCH, MealType.DINNER)),
ALL_MEALS("Tous les moments", listOf(MealType.BREAKFAST, MealType.LUNCH, MealType.SNACK, MealType.DINNER))
}
data class PredictedMealProposal(
val id: String = "pred_${UUID.randomUUID().toString().take(8)}",
val dateEpochDay: Long,
val mealType: MealType,
val recipeId: String? = null,
val title: String,
val servings: Double = 1.0,
val items: List<MealFoodItem> = emptyList(),
val reason: String = "",
val selected: Boolean = true
) {
fun toPlannedMealEntry(): PlannedMealEntry {
return PlannedMealEntry(
id = "",
dateEpochDay = dateEpochDay,
mealType = mealType,
recipeId = recipeId,
customTitle = title.trim(),
servings = servings.coerceAtLeast(0.5),
itemsSerialized = if (recipeId.isNullOrBlank()) {
items.map { it.serialize() }
} else {
emptyList()
},
isConsumed = false
)
}
}
sealed interface WeekPredictionUiState {
data object Idle : WeekPredictionUiState
data object Loading : WeekPredictionUiState
data class Preview(
val proposals: List<PredictedMealProposal>,
val scope: PredictionMealScope,
val defaultServings: Double
) : WeekPredictionUiState
data class Error(
val message: String,
val scope: PredictionMealScope,
val defaultServings: Double
) : WeekPredictionUiState
}