|
|
|
|
@ -50,7 +50,7 @@ struct FederalTournament: Identifiable, Codable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let id: Int |
|
|
|
|
let id: String |
|
|
|
|
var millesime: Int? |
|
|
|
|
var libelle: String? |
|
|
|
|
var tmc: Bool? |
|
|
|
|
@ -92,6 +92,101 @@ struct FederalTournament: Identifiable, Codable { |
|
|
|
|
var prixEspece: Int? |
|
|
|
|
var distanceEnMetres: Double? |
|
|
|
|
|
|
|
|
|
init(from decoder: Decoder) throws { |
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self) |
|
|
|
|
|
|
|
|
|
// Handle id that could be string or int |
|
|
|
|
if let idString = try? container.decode(String.self, forKey: .id) { |
|
|
|
|
id = idString |
|
|
|
|
} else if let idInt = try? container.decode(Int.self, forKey: .id) { |
|
|
|
|
id = String(idInt) |
|
|
|
|
} else { |
|
|
|
|
throw DecodingError.dataCorruptedError(forKey: .id, in: container, |
|
|
|
|
debugDescription: "Expected String or Int for id") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Regular decoding for simple properties |
|
|
|
|
millesime = try container.decodeIfPresent(Int.self, forKey: .millesime) |
|
|
|
|
libelle = try container.decodeIfPresent(String.self, forKey: .libelle) |
|
|
|
|
tmc = try container.decodeIfPresent(Bool.self, forKey: .tmc) |
|
|
|
|
tarifAdulteChampionnat = try container.decodeIfPresent(Double.self, forKey: .tarifAdulteChampionnat) |
|
|
|
|
type = try container.decodeIfPresent(String.self, forKey: .type) |
|
|
|
|
ageReel = try container.decodeIfPresent(Bool.self, forKey: .ageReel) |
|
|
|
|
naturesTerrains = try container.decodeIfPresent([JSONAny].self, forKey: .naturesTerrains) |
|
|
|
|
idsArbitres = try container.decodeIfPresent([JSONAny].self, forKey: .idsArbitres) |
|
|
|
|
tarifJeuneChampionnat = try container.decodeIfPresent(Double.self, forKey: .tarifJeuneChampionnat) |
|
|
|
|
international = try container.decodeIfPresent(Bool.self, forKey: .international) |
|
|
|
|
inscriptionEnLigne = try container.decodeIfPresent(Bool.self, forKey: .inscriptionEnLigne) |
|
|
|
|
categorieTournoi = try container.decodeIfPresent(CategorieTournoi.self, forKey: .categorieTournoi) |
|
|
|
|
prixLot = try container.decodeIfPresent(Int.self, forKey: .prixLot) |
|
|
|
|
paiementEnLigne = try container.decodeIfPresent(Bool.self, forKey: .paiementEnLigne) |
|
|
|
|
reductionAdherentJeune = try container.decodeIfPresent(Double.self, forKey: .reductionAdherentJeune) |
|
|
|
|
reductionAdherentAdulte = try container.decodeIfPresent(Double.self, forKey: .reductionAdherentAdulte) |
|
|
|
|
paiementEnLigneObligatoire = try container.decodeIfPresent(Bool.self, forKey: .paiementEnLigneObligatoire) |
|
|
|
|
villeEngagement = try container.decodeIfPresent(String.self, forKey: .villeEngagement) |
|
|
|
|
senior = try container.decodeIfPresent(Bool.self, forKey: .senior) |
|
|
|
|
veteran = try container.decodeIfPresent(Bool.self, forKey: .veteran) |
|
|
|
|
inscriptionEnLigneEnCours = try container.decodeIfPresent(Bool.self, forKey: .inscriptionEnLigneEnCours) |
|
|
|
|
avecResultatPublie = try container.decodeIfPresent(Bool.self, forKey: .avecResultatPublie) |
|
|
|
|
code = try container.decodeIfPresent(String.self, forKey: .code) |
|
|
|
|
categorieAge = try container.decodeIfPresent(CategorieAge.self, forKey: .categorieAge) |
|
|
|
|
codeComite = try container.decodeIfPresent(String.self, forKey: .codeComite) |
|
|
|
|
installations = try container.decodeIfPresent([JSONAny].self, forKey: .installations) |
|
|
|
|
reductionEpreuveSupplementaireJeune = try container.decodeIfPresent(Double.self, forKey: .reductionEpreuveSupplementaireJeune) |
|
|
|
|
reductionEpreuveSupplementaireAdulte = try container.decodeIfPresent(Double.self, forKey: .reductionEpreuveSupplementaireAdulte) |
|
|
|
|
nomComite = try container.decodeIfPresent(String.self, forKey: .nomComite) |
|
|
|
|
naturesEpreuves = try container.decodeIfPresent([Serie].self, forKey: .naturesEpreuves) |
|
|
|
|
jeune = try container.decodeIfPresent(Bool.self, forKey: .jeune) |
|
|
|
|
courrielEngagement = try container.decodeIfPresent(String.self, forKey: .courrielEngagement) |
|
|
|
|
nomClub = try container.decodeIfPresent(String.self, forKey: .nomClub) |
|
|
|
|
installation = try container.decodeIfPresent(Installation.self, forKey: .installation) |
|
|
|
|
categorieAgeMax = try container.decodeIfPresent(CategorieAge.self, forKey: .categorieAgeMax) |
|
|
|
|
tournoiInterne = try container.decodeIfPresent(Bool.self, forKey: .tournoiInterne) |
|
|
|
|
nomLigue = try container.decodeIfPresent(String.self, forKey: .nomLigue) |
|
|
|
|
nomEngagement = try container.decodeIfPresent(String.self, forKey: .nomEngagement) |
|
|
|
|
codeLigue = try container.decodeIfPresent(String.self, forKey: .codeLigue) |
|
|
|
|
modeleDeBalle = try container.decodeIfPresent(ModeleDeBalle.self, forKey: .modeleDeBalle) |
|
|
|
|
jugeArbitre = try container.decodeIfPresent(JugeArbitre.self, forKey: .jugeArbitre) |
|
|
|
|
adresse2Engagement = try container.decodeIfPresent(String.self, forKey: .adresse2Engagement) |
|
|
|
|
epreuves = try container.decodeIfPresent([Epreuve].self, forKey: .epreuves) |
|
|
|
|
serie = try container.decodeIfPresent(Serie.self, forKey: .serie) |
|
|
|
|
codePostalEngagement = try container.decodeIfPresent(String.self, forKey: .codePostalEngagement) |
|
|
|
|
codeClub = try container.decodeIfPresent(String.self, forKey: .codeClub) |
|
|
|
|
prixEspece = try container.decodeIfPresent(Int.self, forKey: .prixEspece) |
|
|
|
|
distanceEnMetres = try container.decodeIfPresent(Double.self, forKey: .distanceEnMetres) |
|
|
|
|
|
|
|
|
|
// Custom decoding for dateDebut |
|
|
|
|
if let dateContainer = try? container.nestedContainer(keyedBy: DateKeys.self, forKey: .dateDebut) { |
|
|
|
|
if let dateString = try? dateContainer.decode(String.self, forKey: .date) { |
|
|
|
|
let dateFormatter = DateFormatter() |
|
|
|
|
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS" |
|
|
|
|
dateDebut = dateFormatter.date(from: dateString) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Custom decoding for dateFin |
|
|
|
|
if let dateContainer = try? container.nestedContainer(keyedBy: DateKeys.self, forKey: .dateFin) { |
|
|
|
|
if let dateString = try? dateContainer.decode(String.self, forKey: .date) { |
|
|
|
|
let dateFormatter = DateFormatter() |
|
|
|
|
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS" |
|
|
|
|
dateFin = dateFormatter.date(from: dateString) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Custom decoding for dateValidation |
|
|
|
|
if let dateContainer = try? container.nestedContainer(keyedBy: DateKeys.self, forKey: .dateValidation) { |
|
|
|
|
if let dateString = try? dateContainer.decode(String.self, forKey: .date) { |
|
|
|
|
let dateFormatter = DateFormatter() |
|
|
|
|
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSSSS" |
|
|
|
|
dateValidation = dateFormatter.date(from: dateString) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private enum DateKeys: String, CodingKey { |
|
|
|
|
case date |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var dayPeriod: DayPeriod { |
|
|
|
|
if let dateDebut { |
|
|
|
|
let day = dateDebut.get(.weekday) |
|
|
|
|
|