Files
FamilyMealPlanner/MealMood/Models/MealSlot.swift
T
alexandrev-tibco 6fe16d8e29 huecos sin planificar y exclusiones en la lista de la compra
- MealSlot.isSkipped: opcion "No planificar esta comida" en el picker de
  hueco vacio — cuenta como resuelto (semana completa, notificaciones,
  stats) y el autocompletado lo respeta; vista gris con guion, tap para
  desmarcar; viaja en undo, snapshot KV (junto con isEatingOut, que
  faltaba en el payload) y exports (— en imagen, omitido en texto)
- ShoppingItem.isDismissed: "Ya lo tengo" por ingrediente (swipe
  izquierdo) y "Ya esta hecho" por plato entero (boton en la cabecera de
  su seccion); van a la seccion "Ya en casa" con restauracion de un tap,
  y quedan fuera del export de texto. No se borran porque reconcile los
  recrearia
- Esquema CloudKit Development: CD_isSkipped, CD_isDismissed y el record
  type CD_ShoppingItem entero, que no existia — la lista de la compra no
  estaba sincronizando entre dispositivos (mismo bug que photoData)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013H6bXqGX1ygwib1Dm3n3UG
2026-09-01 16:16:34 +02:00

66 lines
2.1 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
/// "Don't plan this meal": counts as resolved (like eating out) but shows
/// as intentionally blank autocomplete leaves it alone.
var isSkipped: 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,
isSkipped: 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
self.isSkipped = isSkipped
}
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]
}
}