import Foundation /// Which days and which meals a given week is planned with. Until 2.1.1 this /// came straight from `AppSettings` and applied to the whole calendar; a week /// can now override it (premium), e.g. add the weekend for a trip or turn on /// breakfast just for the school week. struct WeekSchedule: Equatable { let mealTypes: [MealType] let includeWeekends: Bool /// True when the values come from a per-week override rather than settings. let isCustomized: Bool var dayRange: ClosedRange { includeWeekends ? 0...6 : 0...4 } var lastDay: Int { includeWeekends ? 6 : 4 } } extension AppSettings { /// The schedule applied to every week that has no override of its own. var defaultSchedule: WeekSchedule { WeekSchedule(mealTypes: activeMealTypes, includeWeekends: includeWeekends, isCustomized: false) } /// Resolved schedule for a week: its own override when present, the global /// settings otherwise. /// /// Existing overrides are honoured even when `isPremium` is false — a lapsed /// subscription must not silently delete slots the user already filled. /// Creating or editing an override is what premium gates (see /// `PremiumAccess.canCustomizeWeekSchedule`). func schedule(for plan: WeekPlan?) -> WeekSchedule { guard let plan, plan.hasScheduleOverride else { return defaultSchedule } return WeekSchedule( mealTypes: plan.mealTypesOverride ?? activeMealTypes, includeWeekends: plan.includeWeekendsOverride ?? includeWeekends, isCustomized: true ) } }