From 3b1add024f3f410734d3d6a1f9d236473fa6ae36 Mon Sep 17 00:00:00 2001 From: Trey t Date: Tue, 13 Jan 2026 16:11:53 -0600 Subject: [PATCH] feat(domain): add AnySport protocol for unified sport handling Defines protocol that both Sport enum and DynamicSport will conform to, enabling interchangeable use in UI and planning engine. Co-Authored-By: Claude Opus 4.5 --- SportsTime/Core/Models/Domain/AnySport.swift | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 SportsTime/Core/Models/Domain/AnySport.swift 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 + } + } +}