Files
FamilyMealPlanner/MealMood/Services/PremiumAccess.swift
T
alexandrev-tibco 66128e7a5c premium: configurar días y comidas de una semana concreta
Hasta ahora includeWeekends y activeMealTypes vivían solo en AppSettings y
aplicaban a todo el calendario. WeekPlan puede ahora sobreescribirlos para su
semana (includeWeekendsOverride / mealTypesOverrideRaw) y WeekSchedule resuelve
qué manda en cada semana: su override si lo tiene, los ajustes globales si no.

Todo lo que pintaba días y comidas —planificador, exports, compartir texto,
widget, watch— pasa por settings.schedule(for:), así que una semana con fin de
semana añadido o con desayuno activo se ve igual en todas partes.

Crear o editar el override es premium; los ya guardados se respetan aunque la
suscripción caduque, para no borrar comidas ya planificadas. La hoja avisa y
pide confirmación cuando quitar un día o una comida se lleva por delante algo
ya planificado.

Refs #32

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013su1ttRiMeMYxkZJ1Y3246
2026-09-12 12:05:34 +02:00

30 lines
1.0 KiB
Swift

import Foundation
enum PremiumAccess {
static let freeDishLimit = 15
static let freeFutureWeeks = 1
/// Free users get a taste of on-device ingredient generation; premium is
/// unlimited. Counted per install via UserDefaults.
static let freeIngredientGenerations = 3
private static let generationCountKey = "ingredient_generation_count"
static func hasReachedFreeDishLimit(dishCount: Int, isPremium: Bool) -> Bool {
!isPremium && dishCount >= freeDishLimit
}
/// Per-week schedule overrides (weekend on/off, which meals) are premium.
static func canCustomizeWeekSchedule(isPremium: Bool) -> Bool {
isPremium
}
static func canGenerateIngredients(isPremium: Bool) -> Bool {
isPremium || UserDefaults.standard.integer(forKey: generationCountKey) < freeIngredientGenerations
}
static func recordIngredientGeneration() {
let count = UserDefaults.standard.integer(forKey: generationCountKey)
UserDefaults.standard.set(count + 1, forKey: generationCountKey)
}
}