a0f9fa63d3
- MealSlot.secondaryDishId (opcional, aditivo CloudKit); se limpia al sustituir/quitar/vaciar/marcar comer fuera y viaja en swaps, copia de semana anterior, undo y snapshot KV de iCloud (retrocompatible) - Picker de hueco lleno: toggle "anadir como segundo plato" + boton para quitarlo; HomeViewModel.assignSecondaryDish/removeSecondaryDish - Se muestra "Plato + Segundo" en calendario, widget y export; la lista de la compra incluye los ingredientes del segundo; stats lo cuentan - Evento analytics secondary_dish_added; strings en 6 idiomas Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013H6bXqGX1ygwib1Dm3n3UG
61 lines
1.8 KiB
Swift
61 lines
1.8 KiB
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
// CloudKit-compatible (2.0): no unique constraints, inline defaults everywhere.
|
|
@Model
|
|
final class MealSlot {
|
|
var id: UUID = UUID()
|
|
var dayOfWeek: Int = 0 // 0=Monday, 6=Sunday
|
|
var mealType: String = MealType.dinner.rawValue
|
|
var dishId: UUID?
|
|
/// Optional companion dish ("ensalada + salmón"). Only meaningful while
|
|
/// `dishId` is set; cleared together with it.
|
|
var secondaryDishId: UUID?
|
|
var calendarEventId: String?
|
|
var isRuleOverridden: Bool = false
|
|
var isEatingOut: Bool = false
|
|
|
|
var weekPlan: WeekPlan?
|
|
|
|
init(
|
|
id: UUID = UUID(),
|
|
dayOfWeek: Int,
|
|
mealType: String,
|
|
dishId: UUID? = nil,
|
|
secondaryDishId: UUID? = nil,
|
|
calendarEventId: String? = nil,
|
|
isRuleOverridden: Bool = false,
|
|
isEatingOut: Bool = false
|
|
) {
|
|
self.id = id
|
|
self.dayOfWeek = dayOfWeek
|
|
self.mealType = mealType
|
|
self.dishId = dishId
|
|
self.secondaryDishId = secondaryDishId
|
|
self.calendarEventId = calendarEventId
|
|
self.isRuleOverridden = isRuleOverridden
|
|
self.isEatingOut = isEatingOut
|
|
}
|
|
|
|
var mealTypeEnum: MealType {
|
|
get { MealType(rawValue: mealType) ?? .dinner }
|
|
set { mealType = newValue.rawValue }
|
|
}
|
|
}
|
|
|
|
extension MealSlot {
|
|
static func preferredForDuplicateResolution(_ slots: [MealSlot]) -> MealSlot {
|
|
slots.sorted { lhs, rhs in
|
|
let lhsHasDish = lhs.dishId != nil
|
|
let rhsHasDish = rhs.dishId != nil
|
|
if lhsHasDish != rhsHasDish { return lhsHasDish }
|
|
|
|
let lhsHasEvent = lhs.calendarEventId != nil
|
|
let rhsHasEvent = rhs.calendarEventId != nil
|
|
if lhsHasEvent != rhsHasEvent { return lhsHasEvent }
|
|
|
|
return lhs.id.uuidString < rhs.id.uuidString
|
|
}.first ?? slots[0]
|
|
}
|
|
}
|