feat(domain): add AnySport conformance to Sport enum

Existing Sport enum now conforms to AnySport protocol, enabling
unified handling with future DynamicSport types.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-13 16:17:04 -06:00
parent 3b1add024f
commit e781eaa17c
2 changed files with 69 additions and 7 deletions

View File

@@ -15,9 +15,9 @@ enum Sport: String, Codable, CaseIterable, Identifiable {
case wnba = "WNBA"
case nwsl = "NWSL"
var id: String { rawValue }
nonisolated var id: String { rawValue }
var displayName: String {
nonisolated var displayName: String {
switch self {
case .mlb: return "Major League Baseball"
case .nba: return "National Basketball Association"
@@ -29,7 +29,7 @@ enum Sport: String, Codable, CaseIterable, Identifiable {
}
}
var iconName: String {
nonisolated var iconName: String {
switch self {
case .mlb: return "baseball.fill"
case .nba: return "basketball.fill"
@@ -41,7 +41,7 @@ enum Sport: String, Codable, CaseIterable, Identifiable {
}
}
var color: Color {
nonisolated var color: Color {
switch self {
case .mlb: return .red
case .nba: return .orange
@@ -54,7 +54,7 @@ enum Sport: String, Codable, CaseIterable, Identifiable {
}
/// Season start and end months (1-12). End may be less than start for seasons that wrap around the year.
var seasonMonths: (start: Int, end: Int) {
nonisolated var seasonMonths: (start: Int, end: Int) {
switch self {
case .mlb: return (3, 10) // March - October
case .nba: return (10, 6) // October - June (wraps)
@@ -66,7 +66,7 @@ enum Sport: String, Codable, CaseIterable, Identifiable {
}
}
func isInSeason(for date: Date) -> Bool {
nonisolated func isInSeason(for date: Date) -> Bool {
let calendar = Calendar.current
let month = calendar.component(.month, from: date)
@@ -81,11 +81,20 @@ enum Sport: String, Codable, CaseIterable, Identifiable {
}
/// Currently supported sports
static var supported: [Sport] {
nonisolated static var supported: [Sport] {
[.mlb, .nba, .nfl, .nhl, .mls, .wnba, .nwsl]
}
}
// MARK: - AnySport Conformance
extension Sport: AnySport, @unchecked Sendable {
nonisolated var sportId: String { rawValue }
// Note: displayName, iconName, color, seasonMonths already exist on Sport
// They need nonisolated to satisfy AnySport protocol requirements
}
// MARK: - Array Chunking
extension Array {