diff --git a/SportsTime/Core/Models/Domain/AnySport.swift b/SportsTime/Core/Models/Domain/AnySport.swift new file mode 100644 index 0000000..1d17c91 --- /dev/null +++ b/SportsTime/Core/Models/Domain/AnySport.swift @@ -0,0 +1,44 @@ +// +// AnySport.swift +// SportsTime +// +// Protocol unifying Sport enum and DynamicSport for interchangeable use. +// + +import SwiftUI + +/// Protocol that unifies Sport enum and DynamicSport +/// Allows both to be used interchangeably in UI and planning engine. +protocol AnySport: Identifiable, Hashable, Sendable { + /// Unique identifier string (e.g., "MLB", "xfl") + var sportId: String { get } + + /// Display name for UI (e.g., "Major League Baseball", "XFL Football") + var displayName: String { get } + + /// SF Symbol name for sport icon (e.g., "baseball.fill") + var iconName: String { get } + + /// Theme color for this sport + var color: Color { get } + + /// Season months (start and end, 1-12). End may be less than start for wrap-around seasons. + var seasonMonths: (start: Int, end: Int) { get } +} + +extension AnySport { + /// Check if sport is in season for a given date + func isInSeason(for date: Date) -> Bool { + let calendar = Calendar.current + let month = calendar.component(.month, from: date) + + let (start, end) = seasonMonths + if start <= end { + // Normal range (e.g., March to October) + return month >= start && month <= end + } else { + // Season wraps around year boundary (e.g., October to June) + return month >= start || month <= end + } + } +}