feat(domain): add DynamicSport model for CloudKit-defined sports

Struct representing sports synced from CloudKit. Conforms to AnySport
protocol for interchangeable use with Sport enum in UI and planning.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-13 16:22:02 -06:00
parent e781eaa17c
commit dc278085de
2 changed files with 163 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
//
// DynamicSport.swift
// SportsTime
//
// Domain model for CloudKit-defined sports.
//
import SwiftUI
/// A sport defined via CloudKit, as opposed to the hardcoded Sport enum.
/// Conforms to AnySport for interchangeable use with Sport enum.
nonisolated struct DynamicSport: Identifiable, Hashable, Codable, Sendable {
let id: String
let abbreviation: String
let displayName: String
let iconName: String
let colorHex: String
let seasonStartMonth: Int
let seasonEndMonth: Int
init(
id: String,
abbreviation: String,
displayName: String,
iconName: String,
colorHex: String,
seasonStartMonth: Int,
seasonEndMonth: Int
) {
self.id = id
self.abbreviation = abbreviation
self.displayName = displayName
self.iconName = iconName
self.colorHex = colorHex
self.seasonStartMonth = seasonStartMonth
self.seasonEndMonth = seasonEndMonth
}
}
// MARK: - AnySport Conformance
extension DynamicSport: AnySport {
var sportId: String { id }
var color: Color { Color(hex: colorHex) }
var seasonMonths: (start: Int, end: Int) {
(seasonStartMonth, seasonEndMonth)
}
}