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 <noreply@anthropic.com>
This commit is contained in:
44
SportsTime/Core/Models/Domain/AnySport.swift
Normal file
44
SportsTime/Core/Models/Domain/AnySport.swift
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user