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:
50
SportsTime/Core/Models/Domain/DynamicSport.swift
Normal file
50
SportsTime/Core/Models/Domain/DynamicSport.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user