import Foundation import SwiftData enum GoalUnit: String, Codable, CaseIterable { case seconds case count } enum GoalPeriod: String, Codable, CaseIterable { case daily case weekly case monthly } // Cannot be stored directly in SwiftData; use targetType computed property on GoalEntity. enum TargetType { case duration(min: Double, max: Double?) case count(min: Int, max: Int?) } @Model final class GoalEntity { var id: UUID var title: String var targetValue: Double var targetMax: Double? var unit: GoalUnit var period: GoalPeriod var createdAt: Date var isActive: Bool var task: TaskItem? var tag: TagEntity? var targetType: TargetType { switch unit { case .seconds: return .duration(min: targetValue, max: targetMax) case .count: return .count(min: Int(targetValue), max: targetMax.map(Int.init)) } } init( id: UUID = UUID(), title: String, targetValue: Double, targetMax: Double? = nil, unit: GoalUnit = .seconds, period: GoalPeriod = .daily, createdAt: Date = .now, isActive: Bool = true ) { self.id = id self.title = title self.targetValue = targetValue self.targetMax = targetMax self.unit = unit self.period = period self.createdAt = createdAt self.isActive = isActive } } extension GoalPeriod { var localizedName: String { switch self { case .daily: return String(localized: "goal.period.daily") case .weekly: return String(localized: "goal.period.weekly") case .monthly: return String(localized: "goal.period.monthly") } } }