import Foundation
import SwiftData

@Model
final class MealSlot {
    @Attribute(.unique) var id: UUID
    var dayOfWeek: Int // 0=Monday, 6=Sunday
    var mealType: String // "lunch", "dinner"
    var dishId: UUID?
    var calendarEventId: String?
    var isRuleOverridden: Bool

    var weekPlan: WeekPlan?

    init(
        id: UUID = UUID(),
        dayOfWeek: Int,
        mealType: String,
        dishId: UUID? = nil,
        calendarEventId: String? = nil,
        isRuleOverridden: Bool = false
    ) {
        self.id = id
        self.dayOfWeek = dayOfWeek
        self.mealType = mealType
        self.dishId = dishId
        self.calendarEventId = calendarEventId
        self.isRuleOverridden = isRuleOverridden
    }

    var mealTypeEnum: MealType {
        get { MealType(rawValue: mealType) ?? .dinner }
        set { mealType = newValue.rawValue }
    }
}
