Files
FamilyMealPlanner/MealMood/Models/Dish.swift
T
alexandrev-tibco 7193234024 reglas: plato fijo por dia y comida (ej. tortilla los viernes de cena)
- Dish.fixedDayOfWeek/fixedMealType (opcionales, aditivos para CloudKit)
- Toggle + pickers de dia/comida en el formulario de plato
- AutocompleteEngine: pre-pasada que asigna los platos fijos a su hueco
  antes del bucle MRV, de modo que cuentan para el resto de reglas
- Evento analytics dish_fixed_slot_set; strings en 6 idiomas

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

64 lines
2.0 KiB
Swift

import Foundation
import SwiftData
// CloudKit-compatible (2.0): no unique constraints, inline defaults everywhere.
@Model
final class Dish {
var id: UUID = UUID()
var name: String = ""
var descriptionText: String?
var tagIds: [UUID] = []
var createdAt: Date = Date()
var isPriority: Bool = false
/// Optional ingredient lines (one per entry, e.g. "200g spaghetti").
/// Populated lazily manually or via on-device generation and only for
/// the dishes a user actually shops for. Never required to create a dish.
var ingredients: [String] = []
/// Optional dish photo. Stored outside the main store to keep it light and
/// CloudKit-friendly.
@Attribute(.externalStorage) var photoData: Data?
/// Fixed-slot rule ("tortilla every Friday dinner"): when both are set,
/// autocomplete pins this dish to that weekday+meal before filling the
/// rest of the week. 0=Monday 6=Sunday, matching `MealSlot.dayOfWeek`.
var fixedDayOfWeek: Int?
var fixedMealType: String?
init(
id: UUID = UUID(),
name: String,
descriptionText: String? = nil,
tagIds: [UUID] = [],
createdAt: Date = Date(),
isPriority: Bool = false,
ingredients: [String] = [],
photoData: Data? = nil,
fixedDayOfWeek: Int? = nil,
fixedMealType: String? = nil
) {
self.id = id
self.name = name
self.descriptionText = descriptionText
self.tagIds = tagIds
self.createdAt = createdAt
self.isPriority = isPriority
self.ingredients = ingredients
self.photoData = photoData
self.fixedDayOfWeek = fixedDayOfWeek
self.fixedMealType = fixedMealType
}
}
extension Dish {
static func stableSortedForDisplay(_ dishes: [Dish]) -> [Dish] {
dishes.sorted { lhs, rhs in
if lhs.createdAt != rhs.createdAt {
return lhs.createdAt > rhs.createdAt
}
return lhs.id.uuidString < rhs.id.uuidString
}
}
}