From 0dd3dc16bd7fda526f9f871e9cd678668c9bf56d Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 25 Oct 2024 15:37:04 +0200 Subject: [PATCH] create generator to make base Swift classes --- PadelClub.xcodeproj/project.pbxproj | 254 ++++++++ PadelClub/Data/Club.swift | 127 ++-- PadelClub/Data/Court.swift | 44 +- PadelClub/Data/CustomUser.swift | 265 ++++---- PadelClub/Data/DataStore.swift | 8 +- PadelClub/Data/DateInterval.swift | 55 +- PadelClub/Data/Event.swift | 52 +- PadelClub/Data/Gen/BaseClub.swift | 139 +++++ PadelClub/Data/Gen/BaseCourt.swift | 89 +++ PadelClub/Data/Gen/BaseCustomUser.swift | 197 ++++++ PadelClub/Data/Gen/BaseDateInterval.swift | 78 +++ PadelClub/Data/Gen/BaseEvent.swift | 95 +++ PadelClub/Data/Gen/BaseGroupStage.swift | 110 ++++ PadelClub/Data/Gen/BaseMatch.swift | 158 +++++ PadelClub/Data/Gen/BaseMatchScheduler.swift | 138 +++++ PadelClub/Data/Gen/BaseMonthData.swift | 113 ++++ .../Data/Gen/BasePlayerRegistration.swift | 188 ++++++ PadelClub/Data/Gen/BasePurchase.swift | 95 +++ PadelClub/Data/Gen/BaseRound.swift | 110 ++++ PadelClub/Data/Gen/BaseTeamRegistration.swift | 202 ++++++ PadelClub/Data/Gen/BaseTeamScore.swift | 101 +++ PadelClub/Data/Gen/BaseTournament.swift | 396 ++++++++++++ PadelClub/Data/Gen/Club.json | 90 +++ PadelClub/Data/Gen/Court.json | 47 ++ PadelClub/Data/Gen/CustomUser.json | 136 +++++ PadelClub/Data/Gen/DateInterval.json | 38 ++ PadelClub/Data/Gen/Event.json | 53 ++ PadelClub/Data/Gen/GroupStage.json | 64 ++ PadelClub/Data/Gen/Match.json | 93 +++ PadelClub/Data/Gen/MatchScheduler.json | 75 +++ PadelClub/Data/Gen/MonthData.json | 72 +++ PadelClub/Data/Gen/PlayerRegistration.json | 118 ++++ PadelClub/Data/Gen/Purchase.json | 56 ++ PadelClub/Data/Gen/Round.json | 64 ++ PadelClub/Data/Gen/TeamRegistration.json | 129 ++++ PadelClub/Data/Gen/TeamScore.json | 55 ++ PadelClub/Data/Gen/Tournament.json | 221 +++++++ PadelClub/Data/Gen/generator.py | 504 +++++++++++++++ PadelClub/Data/GroupStage.swift | 114 ++-- PadelClub/Data/Match.swift | 181 +++--- PadelClub/Data/MatchScheduler.swift | 75 +-- PadelClub/Data/MonthData.swift | 29 +- PadelClub/Data/PlayerRegistration.swift | 301 ++++----- PadelClub/Data/Round.swift | 146 ++--- PadelClub/Data/TeamRegistration.swift | 178 +++--- PadelClub/Data/TeamScore.swift | 107 ++-- PadelClub/Data/Tournament.swift | 577 +++++++++--------- .../CodingContainer+Extensions.swift | 8 +- .../NumberFormatter+Extensions.swift | 4 + PadelClub/Utils/FileImportManager.swift | 2 +- .../Views/Cashier/CashierDetailView.swift | 6 +- .../Views/Cashier/CashierSettingsView.swift | 30 +- .../LoserBracketFromGroupStageView.swift | 2 +- PadelClub/Views/Navigation/MainView.swift | 4 +- .../Player/Components/PlayerPayView.swift | 12 +- .../Player/Components/PlayerPopoverView.swift | 2 +- .../Components/PlayerSexPickerView.swift | 22 +- PadelClub/Views/Round/RoundSettingsView.swift | 2 +- .../Views/Tournament/Subscription/Guard.swift | 14 +- .../Tournament/Subscription/Purchase.swift | 118 ++-- .../Subscription/SubscriptionInfoView.swift | 2 +- .../Views/Tournament/TournamentView.swift | 8 +- 62 files changed, 5513 insertions(+), 1260 deletions(-) create mode 100644 PadelClub/Data/Gen/BaseClub.swift create mode 100644 PadelClub/Data/Gen/BaseCourt.swift create mode 100644 PadelClub/Data/Gen/BaseCustomUser.swift create mode 100644 PadelClub/Data/Gen/BaseDateInterval.swift create mode 100644 PadelClub/Data/Gen/BaseEvent.swift create mode 100644 PadelClub/Data/Gen/BaseGroupStage.swift create mode 100644 PadelClub/Data/Gen/BaseMatch.swift create mode 100644 PadelClub/Data/Gen/BaseMatchScheduler.swift create mode 100644 PadelClub/Data/Gen/BaseMonthData.swift create mode 100644 PadelClub/Data/Gen/BasePlayerRegistration.swift create mode 100644 PadelClub/Data/Gen/BasePurchase.swift create mode 100644 PadelClub/Data/Gen/BaseRound.swift create mode 100644 PadelClub/Data/Gen/BaseTeamRegistration.swift create mode 100644 PadelClub/Data/Gen/BaseTeamScore.swift create mode 100644 PadelClub/Data/Gen/BaseTournament.swift create mode 100644 PadelClub/Data/Gen/Club.json create mode 100644 PadelClub/Data/Gen/Court.json create mode 100644 PadelClub/Data/Gen/CustomUser.json create mode 100644 PadelClub/Data/Gen/DateInterval.json create mode 100644 PadelClub/Data/Gen/Event.json create mode 100644 PadelClub/Data/Gen/GroupStage.json create mode 100644 PadelClub/Data/Gen/Match.json create mode 100644 PadelClub/Data/Gen/MatchScheduler.json create mode 100644 PadelClub/Data/Gen/MonthData.json create mode 100644 PadelClub/Data/Gen/PlayerRegistration.json create mode 100644 PadelClub/Data/Gen/Purchase.json create mode 100644 PadelClub/Data/Gen/Round.json create mode 100644 PadelClub/Data/Gen/TeamRegistration.json create mode 100644 PadelClub/Data/Gen/TeamScore.json create mode 100644 PadelClub/Data/Gen/Tournament.json create mode 100644 PadelClub/Data/Gen/generator.py diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 8de2d45..6d8cb6a 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -22,6 +22,98 @@ C45BAE3B2BC6DF10002EEC8A /* SyncedProducts.storekit in Resources */ = {isa = PBXBuildFile; fileRef = C45BAE3A2BC6DF10002EEC8A /* SyncedProducts.storekit */; }; C45BAE442BCA753E002EEC8A /* Purchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45BAE432BCA753E002EEC8A /* Purchase.swift */; }; C4607A7D2C04DDE2004CB781 /* APICallsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4607A7C2C04DDE2004CB781 /* APICallsListView.swift */; }; + C488C7E92CC7D16F0082001F /* generator.py in Resources */ = {isa = PBXBuildFile; fileRef = C488C7E52CC7D1660082001F /* generator.py */; }; + C488C7EA2CC7D16F0082001F /* generator.py in Resources */ = {isa = PBXBuildFile; fileRef = C488C7E52CC7D1660082001F /* generator.py */; }; + C488C7EB2CC7D16F0082001F /* generator.py in Resources */ = {isa = PBXBuildFile; fileRef = C488C7E52CC7D1660082001F /* generator.py */; }; + C488C7F12CC7D22D0082001F /* Club.json in Sources */ = {isa = PBXBuildFile; fileRef = C488C7EC2CC7D2290082001F /* Club.json */; }; + C488C7F22CC7D22D0082001F /* Club.json in Sources */ = {isa = PBXBuildFile; fileRef = C488C7EC2CC7D2290082001F /* Club.json */; }; + C488C7FF2CC7DCB80082001F /* BaseClub.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C7FE2CC7DCB80082001F /* BaseClub.swift */; }; + C488C8002CC7DCB80082001F /* BaseClub.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C7FE2CC7DCB80082001F /* BaseClub.swift */; }; + C488C8012CC7DCB80082001F /* BaseClub.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C7FE2CC7DCB80082001F /* BaseClub.swift */; }; + C488C8032CC7E1E40082001F /* BaseCourt.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8022CC7E1E40082001F /* BaseCourt.swift */; }; + C488C8042CC7E1E40082001F /* BaseCourt.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8022CC7E1E40082001F /* BaseCourt.swift */; }; + C488C8052CC7E1E40082001F /* BaseCourt.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8022CC7E1E40082001F /* BaseCourt.swift */; }; + C488C8202CC7E4240082001F /* Event.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8162CC7E4240082001F /* Event.json */; }; + C488C8212CC7E4240082001F /* Court.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8132CC7E4240082001F /* Court.json */; }; + C488C8222CC7E4240082001F /* Tournament.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81F2CC7E4240082001F /* Tournament.json */; }; + C488C8232CC7E4240082001F /* CustomUser.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8142CC7E4240082001F /* CustomUser.json */; }; + C488C8242CC7E4240082001F /* Round.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81C2CC7E4240082001F /* Round.json */; }; + C488C8252CC7E4240082001F /* MatchScheduler.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8192CC7E4240082001F /* MatchScheduler.json */; }; + C488C8262CC7E4240082001F /* DateInterval.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8152CC7E4240082001F /* DateInterval.json */; }; + C488C8272CC7E4240082001F /* TeamRegistration.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81D2CC7E4240082001F /* TeamRegistration.json */; }; + C488C8282CC7E4240082001F /* GroupStage.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8172CC7E4240082001F /* GroupStage.json */; }; + C488C8292CC7E4240082001F /* MonthData.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81A2CC7E4240082001F /* MonthData.json */; }; + C488C82A2CC7E4240082001F /* TeamScore.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81E2CC7E4240082001F /* TeamScore.json */; }; + C488C82B2CC7E4240082001F /* Match.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8182CC7E4240082001F /* Match.json */; }; + C488C82C2CC7E4240082001F /* PlayerRegistration.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81B2CC7E4240082001F /* PlayerRegistration.json */; }; + C488C82D2CC7E4240082001F /* BaseDateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8072CC7E4240082001F /* BaseDateInterval.swift */; }; + C488C82E2CC7E4240082001F /* BaseMonthData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80C2CC7E4240082001F /* BaseMonthData.swift */; }; + C488C82F2CC7E4240082001F /* BaseTeamRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80F2CC7E4240082001F /* BaseTeamRegistration.swift */; }; + C488C8302CC7E4240082001F /* BaseGroupStage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8092CC7E4240082001F /* BaseGroupStage.swift */; }; + C488C8312CC7E4240082001F /* BaseCustomUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8062CC7E4240082001F /* BaseCustomUser.swift */; }; + C488C8322CC7E4240082001F /* BaseMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80A2CC7E4240082001F /* BaseMatch.swift */; }; + C488C8332CC7E4240082001F /* BaseEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8082CC7E4240082001F /* BaseEvent.swift */; }; + C488C8342CC7E4240082001F /* BaseRound.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80E2CC7E4240082001F /* BaseRound.swift */; }; + C488C8352CC7E4240082001F /* BaseMatchScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80B2CC7E4240082001F /* BaseMatchScheduler.swift */; }; + C488C8372CC7E4240082001F /* BasePlayerRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80D2CC7E4240082001F /* BasePlayerRegistration.swift */; }; + C488C8382CC7E4240082001F /* BaseTeamScore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8102CC7E4240082001F /* BaseTeamScore.swift */; }; + C488C8392CC7E4240082001F /* BaseTournament.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8112CC7E4240082001F /* BaseTournament.swift */; }; + C488C83A2CC7E4240082001F /* Event.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8162CC7E4240082001F /* Event.json */; }; + C488C83B2CC7E4240082001F /* Court.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8132CC7E4240082001F /* Court.json */; }; + C488C83C2CC7E4240082001F /* Tournament.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81F2CC7E4240082001F /* Tournament.json */; }; + C488C83D2CC7E4240082001F /* CustomUser.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8142CC7E4240082001F /* CustomUser.json */; }; + C488C83E2CC7E4240082001F /* Round.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81C2CC7E4240082001F /* Round.json */; }; + C488C83F2CC7E4240082001F /* MatchScheduler.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8192CC7E4240082001F /* MatchScheduler.json */; }; + C488C8402CC7E4240082001F /* DateInterval.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8152CC7E4240082001F /* DateInterval.json */; }; + C488C8412CC7E4240082001F /* TeamRegistration.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81D2CC7E4240082001F /* TeamRegistration.json */; }; + C488C8422CC7E4240082001F /* GroupStage.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8172CC7E4240082001F /* GroupStage.json */; }; + C488C8432CC7E4240082001F /* MonthData.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81A2CC7E4240082001F /* MonthData.json */; }; + C488C8442CC7E4240082001F /* TeamScore.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81E2CC7E4240082001F /* TeamScore.json */; }; + C488C8452CC7E4240082001F /* Match.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8182CC7E4240082001F /* Match.json */; }; + C488C8462CC7E4240082001F /* PlayerRegistration.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81B2CC7E4240082001F /* PlayerRegistration.json */; }; + C488C8472CC7E4240082001F /* BaseDateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8072CC7E4240082001F /* BaseDateInterval.swift */; }; + C488C8482CC7E4240082001F /* BaseMonthData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80C2CC7E4240082001F /* BaseMonthData.swift */; }; + C488C8492CC7E4240082001F /* BaseTeamRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80F2CC7E4240082001F /* BaseTeamRegistration.swift */; }; + C488C84A2CC7E4240082001F /* BaseGroupStage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8092CC7E4240082001F /* BaseGroupStage.swift */; }; + C488C84B2CC7E4240082001F /* BaseCustomUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8062CC7E4240082001F /* BaseCustomUser.swift */; }; + C488C84C2CC7E4240082001F /* BaseMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80A2CC7E4240082001F /* BaseMatch.swift */; }; + C488C84D2CC7E4240082001F /* BaseEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8082CC7E4240082001F /* BaseEvent.swift */; }; + C488C84E2CC7E4240082001F /* BaseRound.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80E2CC7E4240082001F /* BaseRound.swift */; }; + C488C84F2CC7E4240082001F /* BaseMatchScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80B2CC7E4240082001F /* BaseMatchScheduler.swift */; }; + C488C8512CC7E4240082001F /* BasePlayerRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80D2CC7E4240082001F /* BasePlayerRegistration.swift */; }; + C488C8522CC7E4240082001F /* BaseTeamScore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8102CC7E4240082001F /* BaseTeamScore.swift */; }; + C488C8532CC7E4240082001F /* BaseTournament.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8112CC7E4240082001F /* BaseTournament.swift */; }; + C488C8542CC7E4240082001F /* BaseDateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8072CC7E4240082001F /* BaseDateInterval.swift */; }; + C488C8552CC7E4240082001F /* BaseMonthData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80C2CC7E4240082001F /* BaseMonthData.swift */; }; + C488C8562CC7E4240082001F /* BaseTeamRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80F2CC7E4240082001F /* BaseTeamRegistration.swift */; }; + C488C8572CC7E4240082001F /* BaseGroupStage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8092CC7E4240082001F /* BaseGroupStage.swift */; }; + C488C8582CC7E4240082001F /* BaseCustomUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8062CC7E4240082001F /* BaseCustomUser.swift */; }; + C488C8592CC7E4240082001F /* BaseMatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80A2CC7E4240082001F /* BaseMatch.swift */; }; + C488C85A2CC7E4240082001F /* BaseEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8082CC7E4240082001F /* BaseEvent.swift */; }; + C488C85B2CC7E4240082001F /* BaseRound.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80E2CC7E4240082001F /* BaseRound.swift */; }; + C488C85C2CC7E4240082001F /* BaseMatchScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80B2CC7E4240082001F /* BaseMatchScheduler.swift */; }; + C488C85E2CC7E4240082001F /* BasePlayerRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C80D2CC7E4240082001F /* BasePlayerRegistration.swift */; }; + C488C85F2CC7E4240082001F /* BaseTeamScore.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8102CC7E4240082001F /* BaseTeamScore.swift */; }; + C488C8602CC7E4240082001F /* BaseTournament.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C8112CC7E4240082001F /* BaseTournament.swift */; }; + C488C8612CC7E4240082001F /* Event.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8162CC7E4240082001F /* Event.json */; }; + C488C8622CC7E4240082001F /* Court.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8132CC7E4240082001F /* Court.json */; }; + C488C8632CC7E4240082001F /* Tournament.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81F2CC7E4240082001F /* Tournament.json */; }; + C488C8642CC7E4240082001F /* CustomUser.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8142CC7E4240082001F /* CustomUser.json */; }; + C488C8652CC7E4240082001F /* Round.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81C2CC7E4240082001F /* Round.json */; }; + C488C8662CC7E4240082001F /* MatchScheduler.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8192CC7E4240082001F /* MatchScheduler.json */; }; + C488C8672CC7E4240082001F /* DateInterval.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8152CC7E4240082001F /* DateInterval.json */; }; + C488C8682CC7E4240082001F /* TeamRegistration.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81D2CC7E4240082001F /* TeamRegistration.json */; }; + C488C8692CC7E4240082001F /* GroupStage.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8172CC7E4240082001F /* GroupStage.json */; }; + C488C86A2CC7E4240082001F /* MonthData.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81A2CC7E4240082001F /* MonthData.json */; }; + C488C86B2CC7E4240082001F /* TeamScore.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81E2CC7E4240082001F /* TeamScore.json */; }; + C488C86C2CC7E4240082001F /* Match.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8182CC7E4240082001F /* Match.json */; }; + C488C86D2CC7E4240082001F /* PlayerRegistration.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C81B2CC7E4240082001F /* PlayerRegistration.json */; }; + C488C8712CC816410082001F /* Purchase.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8702CC816410082001F /* Purchase.json */; }; + C488C8722CC816410082001F /* BasePurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C86F2CC816410082001F /* BasePurchase.swift */; }; + C488C8732CC816410082001F /* BasePurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C86F2CC816410082001F /* BasePurchase.swift */; }; + C488C8742CC816410082001F /* Purchase.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8702CC816410082001F /* Purchase.json */; }; + C488C8752CC816410082001F /* Purchase.json in Resources */ = {isa = PBXBuildFile; fileRef = C488C8702CC816410082001F /* Purchase.json */; }; + C488C8762CC816410082001F /* BasePurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C488C86F2CC816410082001F /* BasePurchase.swift */; }; C493B37E2C10AD3600862481 /* LoadingViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = C493B37D2C10AD3600862481 /* LoadingViewModifier.swift */; }; C49EF0192BD694290077B5AA /* PurchaseListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C49EF0182BD694290077B5AA /* PurchaseListView.swift */; }; C49EF01B2BD6A1E80077B5AA /* URLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = C49EF01A2BD6A1E80077B5AA /* URLs.swift */; }; @@ -879,6 +971,37 @@ C45BAE3A2BC6DF10002EEC8A /* SyncedProducts.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = SyncedProducts.storekit; sourceTree = ""; }; C45BAE432BCA753E002EEC8A /* Purchase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Purchase.swift; sourceTree = ""; }; C4607A7C2C04DDE2004CB781 /* APICallsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APICallsListView.swift; sourceTree = ""; }; + C488C7E52CC7D1660082001F /* generator.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = generator.py; sourceTree = ""; }; + C488C7EC2CC7D2290082001F /* Club.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Club.json; sourceTree = ""; }; + C488C7FE2CC7DCB80082001F /* BaseClub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseClub.swift; sourceTree = ""; }; + C488C8022CC7E1E40082001F /* BaseCourt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCourt.swift; sourceTree = ""; }; + C488C8062CC7E4240082001F /* BaseCustomUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCustomUser.swift; sourceTree = ""; }; + C488C8072CC7E4240082001F /* BaseDateInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDateInterval.swift; sourceTree = ""; }; + C488C8082CC7E4240082001F /* BaseEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseEvent.swift; sourceTree = ""; }; + C488C8092CC7E4240082001F /* BaseGroupStage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseGroupStage.swift; sourceTree = ""; }; + C488C80A2CC7E4240082001F /* BaseMatch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseMatch.swift; sourceTree = ""; }; + C488C80B2CC7E4240082001F /* BaseMatchScheduler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseMatchScheduler.swift; sourceTree = ""; }; + C488C80C2CC7E4240082001F /* BaseMonthData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseMonthData.swift; sourceTree = ""; }; + C488C80D2CC7E4240082001F /* BasePlayerRegistration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasePlayerRegistration.swift; sourceTree = ""; }; + C488C80E2CC7E4240082001F /* BaseRound.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseRound.swift; sourceTree = ""; }; + C488C80F2CC7E4240082001F /* BaseTeamRegistration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTeamRegistration.swift; sourceTree = ""; }; + C488C8102CC7E4240082001F /* BaseTeamScore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTeamScore.swift; sourceTree = ""; }; + C488C8112CC7E4240082001F /* BaseTournament.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTournament.swift; sourceTree = ""; }; + C488C8132CC7E4240082001F /* Court.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Court.json; sourceTree = ""; }; + C488C8142CC7E4240082001F /* CustomUser.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CustomUser.json; sourceTree = ""; }; + C488C8152CC7E4240082001F /* DateInterval.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = DateInterval.json; sourceTree = ""; }; + C488C8162CC7E4240082001F /* Event.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Event.json; sourceTree = ""; }; + C488C8172CC7E4240082001F /* GroupStage.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = GroupStage.json; sourceTree = ""; }; + C488C8182CC7E4240082001F /* Match.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Match.json; sourceTree = ""; }; + C488C8192CC7E4240082001F /* MatchScheduler.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = MatchScheduler.json; sourceTree = ""; }; + C488C81A2CC7E4240082001F /* MonthData.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = MonthData.json; sourceTree = ""; }; + C488C81B2CC7E4240082001F /* PlayerRegistration.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = PlayerRegistration.json; sourceTree = ""; }; + C488C81C2CC7E4240082001F /* Round.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Round.json; sourceTree = ""; }; + C488C81D2CC7E4240082001F /* TeamRegistration.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TeamRegistration.json; sourceTree = ""; }; + C488C81E2CC7E4240082001F /* TeamScore.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = TeamScore.json; sourceTree = ""; }; + C488C81F2CC7E4240082001F /* Tournament.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Tournament.json; sourceTree = ""; }; + C488C86F2CC816410082001F /* BasePurchase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasePurchase.swift; sourceTree = ""; }; + C488C8702CC816410082001F /* Purchase.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = Purchase.json; sourceTree = ""; }; C493B37D2C10AD3600862481 /* LoadingViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingViewModifier.swift; sourceTree = ""; }; C49EF0182BD694290077B5AA /* PurchaseListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurchaseListView.swift; sourceTree = ""; }; C49EF01A2BD6A1E80077B5AA /* URLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLs.swift; sourceTree = ""; }; @@ -1317,9 +1440,48 @@ name = Frameworks; sourceTree = ""; }; + C488C7FD2CC7D6CD0082001F /* Gen */ = { + isa = PBXGroup; + children = ( + C488C7E52CC7D1660082001F /* generator.py */, + C488C7EC2CC7D2290082001F /* Club.json */, + C488C8132CC7E4240082001F /* Court.json */, + C488C8142CC7E4240082001F /* CustomUser.json */, + C488C8152CC7E4240082001F /* DateInterval.json */, + C488C8162CC7E4240082001F /* Event.json */, + C488C8172CC7E4240082001F /* GroupStage.json */, + C488C8182CC7E4240082001F /* Match.json */, + C488C8192CC7E4240082001F /* MatchScheduler.json */, + C488C81A2CC7E4240082001F /* MonthData.json */, + C488C81B2CC7E4240082001F /* PlayerRegistration.json */, + C488C8702CC816410082001F /* Purchase.json */, + C488C81C2CC7E4240082001F /* Round.json */, + C488C81D2CC7E4240082001F /* TeamRegistration.json */, + C488C81E2CC7E4240082001F /* TeamScore.json */, + C488C81F2CC7E4240082001F /* Tournament.json */, + C488C7FE2CC7DCB80082001F /* BaseClub.swift */, + C488C8022CC7E1E40082001F /* BaseCourt.swift */, + C488C8062CC7E4240082001F /* BaseCustomUser.swift */, + C488C8072CC7E4240082001F /* BaseDateInterval.swift */, + C488C8082CC7E4240082001F /* BaseEvent.swift */, + C488C8092CC7E4240082001F /* BaseGroupStage.swift */, + C488C80A2CC7E4240082001F /* BaseMatch.swift */, + C488C80B2CC7E4240082001F /* BaseMatchScheduler.swift */, + C488C80C2CC7E4240082001F /* BaseMonthData.swift */, + C488C80D2CC7E4240082001F /* BasePlayerRegistration.swift */, + C488C86F2CC816410082001F /* BasePurchase.swift */, + C488C80E2CC7E4240082001F /* BaseRound.swift */, + C488C80F2CC7E4240082001F /* BaseTeamRegistration.swift */, + C488C8102CC7E4240082001F /* BaseTeamScore.swift */, + C488C8112CC7E4240082001F /* BaseTournament.swift */, + ); + path = Gen; + sourceTree = ""; + }; C4A47D5F2B6D3B2D00ADC637 /* Data */ = { isa = PBXGroup; children = ( + C488C7FD2CC7D6CD0082001F /* Gen */, C411C9CC2BF21DAF003017AD /* README.md */, C4A47D5D2B6D38EC00ADC637 /* DataStore.swift */, C4FC2E2A2C2C0E4D0021F3BF /* TournamentStore.swift */, @@ -2138,8 +2300,23 @@ FF1F4B842BFA02A4000B4573 /* groupstagescore-template.html in Resources */, FF1F4B852BFA02A4000B4573 /* player-template.html in Resources */, FF1F4B862BFA02A4000B4573 /* groupstagerow-template.html in Resources */, + C488C8712CC816410082001F /* Purchase.json in Resources */, FF1F4B872BFA02A4000B4573 /* hiddenplayer-template.html in Resources */, + C488C7EB2CC7D16F0082001F /* generator.py in Resources */, FF1F4B882BFA02A4000B4573 /* bracket-template.html in Resources */, + C488C8202CC7E4240082001F /* Event.json in Resources */, + C488C8212CC7E4240082001F /* Court.json in Resources */, + C488C8222CC7E4240082001F /* Tournament.json in Resources */, + C488C8232CC7E4240082001F /* CustomUser.json in Resources */, + C488C8242CC7E4240082001F /* Round.json in Resources */, + C488C8252CC7E4240082001F /* MatchScheduler.json in Resources */, + C488C8262CC7E4240082001F /* DateInterval.json in Resources */, + C488C8272CC7E4240082001F /* TeamRegistration.json in Resources */, + C488C8282CC7E4240082001F /* GroupStage.json in Resources */, + C488C8292CC7E4240082001F /* MonthData.json in Resources */, + C488C82A2CC7E4240082001F /* TeamScore.json in Resources */, + C488C82B2CC7E4240082001F /* Match.json in Resources */, + C488C82C2CC7E4240082001F /* PlayerRegistration.json in Resources */, FF1F4B892BFA02A4000B4573 /* groupstagecol-template.html in Resources */, FF1F4B8A2BFA02A4000B4573 /* groupstage-template.html in Resources */, FF1F4B8B2BFA02A4000B4573 /* groupstageentrant-template.html in Resources */, @@ -2177,8 +2354,23 @@ FF4CC03D2C996C0600151637 /* groupstagescore-template.html in Resources */, FF4CC03E2C996C0600151637 /* player-template.html in Resources */, FF4CC03F2C996C0600151637 /* groupstagerow-template.html in Resources */, + C488C8752CC816410082001F /* Purchase.json in Resources */, FF4CC0402C996C0600151637 /* hiddenplayer-template.html in Resources */, + C488C7E92CC7D16F0082001F /* generator.py in Resources */, FF4CC0412C996C0600151637 /* bracket-template.html in Resources */, + C488C83A2CC7E4240082001F /* Event.json in Resources */, + C488C83B2CC7E4240082001F /* Court.json in Resources */, + C488C83C2CC7E4240082001F /* Tournament.json in Resources */, + C488C83D2CC7E4240082001F /* CustomUser.json in Resources */, + C488C83E2CC7E4240082001F /* Round.json in Resources */, + C488C83F2CC7E4240082001F /* MatchScheduler.json in Resources */, + C488C8402CC7E4240082001F /* DateInterval.json in Resources */, + C488C8412CC7E4240082001F /* TeamRegistration.json in Resources */, + C488C8422CC7E4240082001F /* GroupStage.json in Resources */, + C488C8432CC7E4240082001F /* MonthData.json in Resources */, + C488C8442CC7E4240082001F /* TeamScore.json in Resources */, + C488C8452CC7E4240082001F /* Match.json in Resources */, + C488C8462CC7E4240082001F /* PlayerRegistration.json in Resources */, FF4CC0422C996C0600151637 /* groupstagecol-template.html in Resources */, FF4CC0432C996C0600151637 /* groupstage-template.html in Resources */, FF4CC0442C996C0600151637 /* groupstageentrant-template.html in Resources */, @@ -2202,8 +2394,23 @@ FF70FBBC2C90584900129CC2 /* groupstagescore-template.html in Resources */, FF70FBBD2C90584900129CC2 /* player-template.html in Resources */, FF70FBBE2C90584900129CC2 /* groupstagerow-template.html in Resources */, + C488C8742CC816410082001F /* Purchase.json in Resources */, FF70FBBF2C90584900129CC2 /* hiddenplayer-template.html in Resources */, + C488C7EA2CC7D16F0082001F /* generator.py in Resources */, FF70FBC02C90584900129CC2 /* bracket-template.html in Resources */, + C488C8612CC7E4240082001F /* Event.json in Resources */, + C488C8622CC7E4240082001F /* Court.json in Resources */, + C488C8632CC7E4240082001F /* Tournament.json in Resources */, + C488C8642CC7E4240082001F /* CustomUser.json in Resources */, + C488C8652CC7E4240082001F /* Round.json in Resources */, + C488C8662CC7E4240082001F /* MatchScheduler.json in Resources */, + C488C8672CC7E4240082001F /* DateInterval.json in Resources */, + C488C8682CC7E4240082001F /* TeamRegistration.json in Resources */, + C488C8692CC7E4240082001F /* GroupStage.json in Resources */, + C488C86A2CC7E4240082001F /* MonthData.json in Resources */, + C488C86B2CC7E4240082001F /* TeamScore.json in Resources */, + C488C86C2CC7E4240082001F /* Match.json in Resources */, + C488C86D2CC7E4240082001F /* PlayerRegistration.json in Resources */, FF70FBC12C90584900129CC2 /* groupstagecol-template.html in Resources */, FF70FBC22C90584900129CC2 /* groupstage-template.html in Resources */, FF70FBC32C90584900129CC2 /* groupstageentrant-template.html in Resources */, @@ -2258,6 +2465,7 @@ FF7091682B90F79F00AB08DA /* TournamentCellView.swift in Sources */, FF6EC9042B9479F500EA7F5A /* Sequence+Extensions.swift in Sources */, FF9267FA2BCE78EC0080F940 /* CashierDetailView.swift in Sources */, + C488C8722CC816410082001F /* BasePurchase.swift in Sources */, FFE103082C353B7600684FC9 /* EventClubSettingsView.swift in Sources */, C4A47DB32B86387500ADC637 /* AccountView.swift in Sources */, FFCEDA4C2C2C08EA00F8C0F2 /* PlayersWithoutContactView.swift in Sources */, @@ -2278,6 +2486,18 @@ FF8F263B2BAD528600650388 /* EventCreationView.swift in Sources */, FFC1E1082BAC29FC008D6F59 /* LocationManager.swift in Sources */, C4C01D982C481C0C0059087C /* CapsuleViewModifier.swift in Sources */, + C488C82D2CC7E4240082001F /* BaseDateInterval.swift in Sources */, + C488C82E2CC7E4240082001F /* BaseMonthData.swift in Sources */, + C488C82F2CC7E4240082001F /* BaseTeamRegistration.swift in Sources */, + C488C8302CC7E4240082001F /* BaseGroupStage.swift in Sources */, + C488C8312CC7E4240082001F /* BaseCustomUser.swift in Sources */, + C488C8322CC7E4240082001F /* BaseMatch.swift in Sources */, + C488C8332CC7E4240082001F /* BaseEvent.swift in Sources */, + C488C8342CC7E4240082001F /* BaseRound.swift in Sources */, + C488C8352CC7E4240082001F /* BaseMatchScheduler.swift in Sources */, + C488C8372CC7E4240082001F /* BasePlayerRegistration.swift in Sources */, + C488C8382CC7E4240082001F /* BaseTeamScore.swift in Sources */, + C488C8392CC7E4240082001F /* BaseTournament.swift in Sources */, FF6087EC2BE26A2F004E1E47 /* BroadcastView.swift in Sources */, FFF964552BC266CF00EEF017 /* SchedulerView.swift in Sources */, FFA1B1292BB71773006CE248 /* PadelClubButtonView.swift in Sources */, @@ -2320,6 +2540,7 @@ FF3795662B9399AA004EA093 /* Persistence.swift in Sources */, FFCF76072C3BE9BC006C8C3D /* CloseDatePicker.swift in Sources */, FF1DF49B2BD8D23900822FA0 /* BarButtonView.swift in Sources */, + C488C8052CC7E1E40082001F /* BaseCourt.swift in Sources */, FFF964502BC25E3700EEF017 /* PlanningView.swift in Sources */, FF967CEC2BAECB9900A9A3BD /* Match.swift in Sources */, FF8F264B2BAE0B4100650388 /* TournamentLevelPickerView.swift in Sources */, @@ -2432,6 +2653,7 @@ FF089EBD2BB0287D00F0AEC7 /* PlayerView.swift in Sources */, FF967D032BAEF0C000A9A3BD /* MatchDetailView.swift in Sources */, FFF1D2CB2C4A22B200C8D33D /* ExportFormat.swift in Sources */, + C488C8012CC7DCB80082001F /* BaseClub.swift in Sources */, FF967D0F2BAF63B000A9A3BD /* PlayerBlockView.swift in Sources */, C4A47D922B7BBBEC00ADC637 /* StoreItem.swift in Sources */, FFB9C8712BBADDE200A0EF4F /* Selectable.swift in Sources */, @@ -2535,6 +2757,7 @@ FF4CBF6B2C996C0600151637 /* Calendar+Extensions.swift in Sources */, FF4CBF6C2C996C0600151637 /* TeamScore.swift in Sources */, FF4CBF6D2C996C0600151637 /* EditablePlayerView.swift in Sources */, + C488C7F12CC7D22D0082001F /* Club.json in Sources */, FF4CBF6E2C996C0600151637 /* PlayerDetailView.swift in Sources */, FF4CBF6F2C996C0600151637 /* ListRowViewModifier.swift in Sources */, FF4CBF702C996C0600151637 /* PresentationContext.swift in Sources */, @@ -2548,6 +2771,18 @@ FF4CBF782C996C0600151637 /* EventCreationView.swift in Sources */, FF4CBF792C996C0600151637 /* LocationManager.swift in Sources */, FF4CBF7A2C996C0600151637 /* CapsuleViewModifier.swift in Sources */, + C488C8472CC7E4240082001F /* BaseDateInterval.swift in Sources */, + C488C8482CC7E4240082001F /* BaseMonthData.swift in Sources */, + C488C8492CC7E4240082001F /* BaseTeamRegistration.swift in Sources */, + C488C84A2CC7E4240082001F /* BaseGroupStage.swift in Sources */, + C488C84B2CC7E4240082001F /* BaseCustomUser.swift in Sources */, + C488C84C2CC7E4240082001F /* BaseMatch.swift in Sources */, + C488C84D2CC7E4240082001F /* BaseEvent.swift in Sources */, + C488C84E2CC7E4240082001F /* BaseRound.swift in Sources */, + C488C84F2CC7E4240082001F /* BaseMatchScheduler.swift in Sources */, + C488C8512CC7E4240082001F /* BasePlayerRegistration.swift in Sources */, + C488C8522CC7E4240082001F /* BaseTeamScore.swift in Sources */, + C488C8532CC7E4240082001F /* BaseTournament.swift in Sources */, FF4CBF7B2C996C0600151637 /* BroadcastView.swift in Sources */, FF4CBF7C2C996C0600151637 /* SchedulerView.swift in Sources */, FF4CBF7D2C996C0600151637 /* PadelClubButtonView.swift in Sources */, @@ -2564,6 +2799,7 @@ FF4CBF882C996C0600151637 /* TeamRowView.swift in Sources */, FF4CBF892C996C0600151637 /* ContactManager.swift in Sources */, FF4CBF8A2C996C0600151637 /* AppDelegate.swift in Sources */, + C488C8762CC816410082001F /* BasePurchase.swift in Sources */, FF4CBF8B2C996C0600151637 /* SubscriptionInfoView.swift in Sources */, FF4CBF8C2C996C0600151637 /* EditScoreView.swift in Sources */, FF4CBF8D2C996C0600151637 /* TournamentOrganizerView.swift in Sources */, @@ -2590,6 +2826,7 @@ FF4CBFA22C996C0600151637 /* Persistence.swift in Sources */, FF4CBFA32C996C0600151637 /* CloseDatePicker.swift in Sources */, FF4CBFA42C996C0600151637 /* BarButtonView.swift in Sources */, + C488C8042CC7E1E40082001F /* BaseCourt.swift in Sources */, FF4CBFA52C996C0600151637 /* PlanningView.swift in Sources */, FF4CBFA62C996C0600151637 /* Match.swift in Sources */, FF4CBFA72C996C0600151637 /* TournamentLevelPickerView.swift in Sources */, @@ -2702,6 +2939,7 @@ FF4CC0112C996C0600151637 /* PlayerView.swift in Sources */, FF4CC0122C996C0600151637 /* MatchDetailView.swift in Sources */, FF4CC0132C996C0600151637 /* ExportFormat.swift in Sources */, + C488C7FF2CC7DCB80082001F /* BaseClub.swift in Sources */, FF4CC0142C996C0600151637 /* PlayerBlockView.swift in Sources */, FF4CC0152C996C0600151637 /* StoreItem.swift in Sources */, FF4CC0162C996C0600151637 /* Selectable.swift in Sources */, @@ -2783,6 +3021,7 @@ FF70FAEA2C90584900129CC2 /* Calendar+Extensions.swift in Sources */, FF70FAEB2C90584900129CC2 /* TeamScore.swift in Sources */, FF70FAEC2C90584900129CC2 /* EditablePlayerView.swift in Sources */, + C488C7F22CC7D22D0082001F /* Club.json in Sources */, FF70FAED2C90584900129CC2 /* PlayerDetailView.swift in Sources */, FF70FAEE2C90584900129CC2 /* ListRowViewModifier.swift in Sources */, FF70FAEF2C90584900129CC2 /* PresentationContext.swift in Sources */, @@ -2796,6 +3035,18 @@ FF70FAF72C90584900129CC2 /* EventCreationView.swift in Sources */, FF70FAF82C90584900129CC2 /* LocationManager.swift in Sources */, FF70FAF92C90584900129CC2 /* CapsuleViewModifier.swift in Sources */, + C488C8542CC7E4240082001F /* BaseDateInterval.swift in Sources */, + C488C8552CC7E4240082001F /* BaseMonthData.swift in Sources */, + C488C8562CC7E4240082001F /* BaseTeamRegistration.swift in Sources */, + C488C8572CC7E4240082001F /* BaseGroupStage.swift in Sources */, + C488C8582CC7E4240082001F /* BaseCustomUser.swift in Sources */, + C488C8592CC7E4240082001F /* BaseMatch.swift in Sources */, + C488C85A2CC7E4240082001F /* BaseEvent.swift in Sources */, + C488C85B2CC7E4240082001F /* BaseRound.swift in Sources */, + C488C85C2CC7E4240082001F /* BaseMatchScheduler.swift in Sources */, + C488C85E2CC7E4240082001F /* BasePlayerRegistration.swift in Sources */, + C488C85F2CC7E4240082001F /* BaseTeamScore.swift in Sources */, + C488C8602CC7E4240082001F /* BaseTournament.swift in Sources */, FF70FAFA2C90584900129CC2 /* BroadcastView.swift in Sources */, FF70FAFB2C90584900129CC2 /* SchedulerView.swift in Sources */, FF70FAFC2C90584900129CC2 /* PadelClubButtonView.swift in Sources */, @@ -2812,6 +3063,7 @@ FF70FB072C90584900129CC2 /* TeamRowView.swift in Sources */, FF70FB082C90584900129CC2 /* ContactManager.swift in Sources */, FF70FB092C90584900129CC2 /* AppDelegate.swift in Sources */, + C488C8732CC816410082001F /* BasePurchase.swift in Sources */, FF70FB0A2C90584900129CC2 /* SubscriptionInfoView.swift in Sources */, FF70FB0B2C90584900129CC2 /* EditScoreView.swift in Sources */, FF70FB0C2C90584900129CC2 /* TournamentOrganizerView.swift in Sources */, @@ -2838,6 +3090,7 @@ FF70FB212C90584900129CC2 /* Persistence.swift in Sources */, FF70FB222C90584900129CC2 /* CloseDatePicker.swift in Sources */, FF70FB232C90584900129CC2 /* BarButtonView.swift in Sources */, + C488C8032CC7E1E40082001F /* BaseCourt.swift in Sources */, FF70FB242C90584900129CC2 /* PlanningView.swift in Sources */, FF70FB252C90584900129CC2 /* Match.swift in Sources */, FF70FB262C90584900129CC2 /* TournamentLevelPickerView.swift in Sources */, @@ -2950,6 +3203,7 @@ FF70FB902C90584900129CC2 /* PlayerView.swift in Sources */, FF70FB912C90584900129CC2 /* MatchDetailView.swift in Sources */, FF70FB922C90584900129CC2 /* ExportFormat.swift in Sources */, + C488C8002CC7DCB80082001F /* BaseClub.swift in Sources */, FF70FB932C90584900129CC2 /* PlayerBlockView.swift in Sources */, FF70FB942C90584900129CC2 /* StoreItem.swift in Sources */, FF70FB952C90584900129CC2 /* Selectable.swift in Sources */, diff --git a/PadelClub/Data/Club.swift b/PadelClub/Data/Club.swift index b7dc5ad..41b6c2e 100644 --- a/PadelClub/Data/Club.swift +++ b/PadelClub/Data/Club.swift @@ -10,34 +10,34 @@ import SwiftUI import LeStorage @Observable -final class Club: ModelObject, SyncedStorable { +final class Club: BaseClub { - static func resourceName() -> String { return "clubs" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [.get] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var creator: String? - var name: String - var acronym: String - var phone: String? - var code: String? - //var federalClubData: Data? - var address: String? - var city: String? - var zipCode: String? - var latitude: Double? - var longitude: Double? - var courtCount: Int = 2 - var broadcastCode: String? -// var alphabeticalName: Bool = false +// static func resourceName() -> String { return "clubs" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [.get] } +// static func filterByStoreIdentifier() -> Bool { return false } +// static var relationshipNames: [String] = [] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var creator: String? +// var name: String +// var acronym: String +// var phone: String? +// var code: String? +// //var federalClubData: Data? +// var address: String? +// var city: String? +// var zipCode: String? +// var latitude: Double? +// var longitude: Double? +// var courtCount: Int = 2 +// var broadcastCode: String? +//// var alphabeticalName: Bool = false var storeId: String? { return nil } internal init(creator: String? = nil, name: String, acronym: String? = nil, phone: String? = nil, code: String? = nil, address: String? = nil, city: String? = nil, zipCode: String? = nil, latitude: Double? = nil, longitude: Double? = nil, courtCount: Int = 2, broadcastCode: String? = nil) { - self.lastUpdate = Date() + super.init() self.name = name self.creator = creator @@ -52,12 +52,11 @@ final class Club: ModelObject, SyncedStorable { self.courtCount = courtCount self.broadcastCode = broadcastCode - super.init() } -// required init(from decoder: any Decoder) throws { -// fatalError("init(from:) has not been implemented") -// } + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) + } override func copyFromServerInstance(_ instance: any Storable) -> Bool { guard let copy = instance as? Club else { return false } @@ -91,43 +90,43 @@ final class Club: ModelObject, SyncedStorable { DataStore.shared.courts.deleteDependencies(customizedCourts) } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _creator = "creator" - case _name = "name" - case _acronym = "acronym" - case _phone = "phone" - case _code = "code" - case _address = "address" - case _city = "city" - case _zipCode = "zipCode" - case _latitude = "latitude" - case _longitude = "longitude" - case _courtCount = "courtCount" - case _broadcastCode = "broadcastCode" -// case _alphabeticalName = "alphabeticalName" - } - - func encode(to encoder: Encoder) throws { - - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(creator, forKey: ._creator) - try container.encode(name, forKey: ._name) - try container.encode(acronym, forKey: ._acronym) - try container.encode(phone, forKey: ._phone) - try container.encode(code, forKey: ._code) - try container.encode(address, forKey: ._address) - try container.encode(city, forKey: ._city) - try container.encode(zipCode, forKey: ._zipCode) - try container.encode(latitude, forKey: ._latitude) - try container.encode(longitude, forKey: ._longitude) - try container.encode(courtCount, forKey: ._courtCount) - try container.encode(broadcastCode, forKey: ._broadcastCode) - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _lastUpdate = "lastUpdate" +// case _creator = "creator" +// case _name = "name" +// case _acronym = "acronym" +// case _phone = "phone" +// case _code = "code" +// case _address = "address" +// case _city = "city" +// case _zipCode = "zipCode" +// case _latitude = "latitude" +// case _longitude = "longitude" +// case _courtCount = "courtCount" +// case _broadcastCode = "broadcastCode" +//// case _alphabeticalName = "alphabeticalName" +// } +// +// func encode(to encoder: Encoder) throws { +// +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(creator, forKey: ._creator) +// try container.encode(name, forKey: ._name) +// try container.encode(acronym, forKey: ._acronym) +// try container.encode(phone, forKey: ._phone) +// try container.encode(code, forKey: ._code) +// try container.encode(address, forKey: ._address) +// try container.encode(city, forKey: ._city) +// try container.encode(zipCode, forKey: ._zipCode) +// try container.encode(latitude, forKey: ._latitude) +// try container.encode(longitude, forKey: ._longitude) +// try container.encode(courtCount, forKey: ._courtCount) +// try container.encode(broadcastCode, forKey: ._broadcastCode) +// } } diff --git a/PadelClub/Data/Court.swift b/PadelClub/Data/Court.swift index 3853c3a..d438f2e 100644 --- a/PadelClub/Data/Court.swift +++ b/PadelClub/Data/Court.swift @@ -10,28 +10,18 @@ import SwiftUI import LeStorage @Observable -final class Court : ModelObject, SyncedStorable { +final class Court: BaseCourt { - static func resourceName() -> String { return "courts" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - static func == (lhs: Court, rhs: Court) -> Bool { lhs.id == rhs.id } - var id: String = Store.randomId() - var lastUpdate: Date - var index: Int - var club: String - var name: String? - var exitAllowed: Bool = false - var indoor: Bool = false - var storeId: String? { return nil } init(index: Int, club: String, name: String? = nil, exitAllowed: Bool = false, indoor: Bool = false) { + + super.init() + self.index = index self.lastUpdate = Date() self.club = club @@ -40,6 +30,10 @@ final class Court : ModelObject, SyncedStorable { self.indoor = indoor } + required init(from decoder: Decoder) throws { + fatalError("init(from:) has not been implemented") + } + func courtTitle() -> String { self.name ?? courtIndexTitle() } @@ -59,26 +53,4 @@ final class Court : ModelObject, SyncedStorable { override func deleteDependencies() { } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _index = "index" - case _club = "club" - case _name = "name" - case _exitAllowed = "exitAllowed" - case _indoor = "indoor" - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(index, forKey: ._index) - try container.encode(club, forKey: ._club) - try container.encode(name, forKey: ._name) - try container.encode(exitAllowed, forKey: ._exitAllowed) - try container.encode(indoor, forKey: ._indoor) - } - } diff --git a/PadelClub/Data/CustomUser.swift b/PadelClub/Data/CustomUser.swift index 3d0b71d..053f02f 100644 --- a/PadelClub/Data/CustomUser.swift +++ b/PadelClub/Data/CustomUser.swift @@ -15,50 +15,57 @@ enum UserRight: Int, Codable { } @Observable -class CustomUser: ModelObject, UserBase, SyncedStorable { +class CustomUser: BaseCustomUser, UserBase { - static func resourceName() -> String { "users" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [.post] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - public var id: String = Store.randomId() - var lastUpdate: Date - public var username: String - public var email: String - var clubs: [String] = [] - var umpireCode: String? - var licenceId: String? - var firstName: String - var lastName: String - var phone: String? - var country: String? - - var summonsMessageBody : String? = nil - var summonsMessageSignature: String? = nil - var summonsAvailablePaymentMethods: String? = nil - var summonsDisplayFormat: Bool = false - var summonsDisplayEntryFee: Bool = false - var summonsUseFullCustomMessage: Bool = false - var matchFormatsDefaultDuration: [MatchFormat: Int]? = nil - var bracketMatchFormatPreference: MatchFormat? - var groupStageMatchFormatPreference: MatchFormat? - var loserBracketMatchFormatPreference: MatchFormat? - var loserBracketMode: LoserBracketMode = .automatic - - var deviceId: String? +// static func resourceName() -> String { "users" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [.post] } +// static func filterByStoreIdentifier() -> Bool { return false } +// static var relationshipNames: [String] = [] +// +// public var id: String = Store.randomId() +// var lastUpdate: Date +// public var username: String +// public var email: String +// var clubs: [String] = [] +// var umpireCode: String? +// var licenceId: String? +// var firstName: String +// var lastName: String +// var phone: String? +// var country: String? +// +// var summonsMessageBody : String? = nil +// var summonsMessageSignature: String? = nil +// var summonsAvailablePaymentMethods: String? = nil +// var summonsDisplayFormat: Bool = false +// var summonsDisplayEntryFee: Bool = false +// var summonsUseFullCustomMessage: Bool = false +// var matchFormatsDefaultDuration: [MatchFormat: Int]? = nil +// var bracketMatchFormatPreference: MatchFormat? +// var groupStageMatchFormatPreference: MatchFormat? +// var loserBracketMatchFormatPreference: MatchFormat? +// var loserBracketMode: LoserBracketMode = .automatic +// +// var deviceId: String? var storeId: String? { return nil } init(username: String, email: String, firstName: String, lastName: String, phone: String?, country: String?, loserBracketMode: LoserBracketMode = .automatic) { - self.lastUpdate = Date() - self.username = username - self.firstName = firstName - self.lastName = lastName - self.email = email - self.phone = phone - self.country = country - self.loserBracketMode = loserBracketMode + super.init(username: username, email: email, firstName: firstName, lastName: lastName, phone: phone, country: country, loserBracketMode: loserBracketMode) + + +// self.lastUpdate = Date() +// self.username = username +// self.firstName = firstName +// self.lastName = lastName +// self.email = email +// self.phone = phone +// self.country = country +// self.loserBracketMode = loserBracketMode + } + + required init(from decoder: Decoder) throws { + try super.init(from: decoder) } public func uuid() throws -> UUID { @@ -123,96 +130,96 @@ class CustomUser: ModelObject, UserBase, SyncedStorable { } } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _username = "username" - case _email = "email" - case _clubs = "clubs" - case _umpireCode = "umpireCode" - case _licenceId = "licenceId" - case _firstName = "firstName" - case _lastName = "lastName" - case _phone = "phone" - case _country = "country" - case _summonsMessageBody = "summonsMessageBody" - case _summonsMessageSignature = "summonsMessageSignature" - case _summonsAvailablePaymentMethods = "summonsAvailablePaymentMethods" - case _summonsDisplayFormat = "summonsDisplayFormat" - case _summonsDisplayEntryFee = "summonsDisplayEntryFee" - case _summonsUseFullCustomMessage = "summonsUseFullCustomMessage" - case _matchFormatsDefaultDuration = "matchFormatsDefaultDuration" - case _bracketMatchFormatPreference = "bracketMatchFormatPreference" - case _groupStageMatchFormatPreference = "groupStageMatchFormatPreference" - case _loserBracketMatchFormatPreference = "loserBracketMatchFormatPreference" - case _deviceId = "deviceId" - case _loserBracketMode = "loserBracketMode" - } - - public required init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - // Required properties - id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() - lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() - username = try container.decode(String.self, forKey: ._username) - email = try container.decode(String.self, forKey: ._email) - firstName = try container.decode(String.self, forKey: ._firstName) - lastName = try container.decode(String.self, forKey: ._lastName) - - // Optional properties - clubs = try container.decodeIfPresent([String].self, forKey: ._clubs) ?? [] - umpireCode = try container.decodeIfPresent(String.self, forKey: ._umpireCode) - licenceId = try container.decodeIfPresent(String.self, forKey: ._licenceId) - phone = try container.decodeIfPresent(String.self, forKey: ._phone) - country = try container.decodeIfPresent(String.self, forKey: ._country) - - // Summons-related properties - summonsMessageBody = try container.decodeIfPresent(String.self, forKey: ._summonsMessageBody) - summonsMessageSignature = try container.decodeIfPresent(String.self, forKey: ._summonsMessageSignature) - summonsAvailablePaymentMethods = try container.decodeIfPresent(String.self, forKey: ._summonsAvailablePaymentMethods) - summonsDisplayFormat = try container.decodeIfPresent(Bool.self, forKey: ._summonsDisplayFormat) ?? false - summonsDisplayEntryFee = try container.decodeIfPresent(Bool.self, forKey: ._summonsDisplayEntryFee) ?? false - summonsUseFullCustomMessage = try container.decodeIfPresent(Bool.self, forKey: ._summonsUseFullCustomMessage) ?? false - - // Match-related properties - matchFormatsDefaultDuration = try container.decodeIfPresent([MatchFormat: Int].self, forKey: ._matchFormatsDefaultDuration) - bracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._bracketMatchFormatPreference) - groupStageMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._groupStageMatchFormatPreference) - loserBracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserBracketMatchFormatPreference) - loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(username, forKey: ._username) - try container.encode(email, forKey: ._email) - try container.encode(clubs, forKey: ._clubs) - - try container.encode(umpireCode, forKey: ._umpireCode) - try container.encode(licenceId, forKey: ._licenceId) - try container.encode(firstName, forKey: ._firstName) - try container.encode(lastName, forKey: ._lastName) - try container.encode(phone, forKey: ._phone) - try container.encode(country, forKey: ._country) - try container.encode(summonsMessageBody, forKey: ._summonsMessageBody) - try container.encode(summonsMessageSignature, forKey: ._summonsMessageSignature) - try container.encode(summonsAvailablePaymentMethods, forKey: ._summonsAvailablePaymentMethods) - try container.encode(summonsDisplayFormat, forKey: ._summonsDisplayFormat) - try container.encode(summonsDisplayEntryFee, forKey: ._summonsDisplayEntryFee) - try container.encode(summonsUseFullCustomMessage, forKey: ._summonsUseFullCustomMessage) - - try container.encode(matchFormatsDefaultDuration, forKey: ._matchFormatsDefaultDuration) - try container.encode(bracketMatchFormatPreference, forKey: ._bracketMatchFormatPreference) - try container.encode(groupStageMatchFormatPreference, forKey: ._groupStageMatchFormatPreference) - try container.encode(loserBracketMatchFormatPreference, forKey: ._loserBracketMatchFormatPreference) - try container.encode(deviceId, forKey: ._deviceId) - - try container.encode(loserBracketMode, forKey: ._loserBracketMode) - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _lastUpdate = "lastUpdate" +// case _username = "username" +// case _email = "email" +// case _clubs = "clubs" +// case _umpireCode = "umpireCode" +// case _licenceId = "licenceId" +// case _firstName = "firstName" +// case _lastName = "lastName" +// case _phone = "phone" +// case _country = "country" +// case _summonsMessageBody = "summonsMessageBody" +// case _summonsMessageSignature = "summonsMessageSignature" +// case _summonsAvailablePaymentMethods = "summonsAvailablePaymentMethods" +// case _summonsDisplayFormat = "summonsDisplayFormat" +// case _summonsDisplayEntryFee = "summonsDisplayEntryFee" +// case _summonsUseFullCustomMessage = "summonsUseFullCustomMessage" +// case _matchFormatsDefaultDuration = "matchFormatsDefaultDuration" +// case _bracketMatchFormatPreference = "bracketMatchFormatPreference" +// case _groupStageMatchFormatPreference = "groupStageMatchFormatPreference" +// case _loserBracketMatchFormatPreference = "loserBracketMatchFormatPreference" +// case _deviceId = "deviceId" +// case _loserBracketMode = "loserBracketMode" +// } +// +// public required init(from decoder: Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// +// // Required properties +// id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() +// lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() +// username = try container.decode(String.self, forKey: ._username) +// email = try container.decode(String.self, forKey: ._email) +// firstName = try container.decode(String.self, forKey: ._firstName) +// lastName = try container.decode(String.self, forKey: ._lastName) +// +// // Optional properties +// clubs = try container.decodeIfPresent([String].self, forKey: ._clubs) ?? [] +// umpireCode = try container.decodeIfPresent(String.self, forKey: ._umpireCode) +// licenceId = try container.decodeIfPresent(String.self, forKey: ._licenceId) +// phone = try container.decodeIfPresent(String.self, forKey: ._phone) +// country = try container.decodeIfPresent(String.self, forKey: ._country) +// +// // Summons-related properties +// summonsMessageBody = try container.decodeIfPresent(String.self, forKey: ._summonsMessageBody) +// summonsMessageSignature = try container.decodeIfPresent(String.self, forKey: ._summonsMessageSignature) +// summonsAvailablePaymentMethods = try container.decodeIfPresent(String.self, forKey: ._summonsAvailablePaymentMethods) +// summonsDisplayFormat = try container.decodeIfPresent(Bool.self, forKey: ._summonsDisplayFormat) ?? false +// summonsDisplayEntryFee = try container.decodeIfPresent(Bool.self, forKey: ._summonsDisplayEntryFee) ?? false +// summonsUseFullCustomMessage = try container.decodeIfPresent(Bool.self, forKey: ._summonsUseFullCustomMessage) ?? false +// +// // Match-related properties +// matchFormatsDefaultDuration = try container.decodeIfPresent([MatchFormat: Int].self, forKey: ._matchFormatsDefaultDuration) +// bracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._bracketMatchFormatPreference) +// groupStageMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._groupStageMatchFormatPreference) +// loserBracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserBracketMatchFormatPreference) +// loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(username, forKey: ._username) +// try container.encode(email, forKey: ._email) +// try container.encode(clubs, forKey: ._clubs) +// +// try container.encode(umpireCode, forKey: ._umpireCode) +// try container.encode(licenceId, forKey: ._licenceId) +// try container.encode(firstName, forKey: ._firstName) +// try container.encode(lastName, forKey: ._lastName) +// try container.encode(phone, forKey: ._phone) +// try container.encode(country, forKey: ._country) +// try container.encode(summonsMessageBody, forKey: ._summonsMessageBody) +// try container.encode(summonsMessageSignature, forKey: ._summonsMessageSignature) +// try container.encode(summonsAvailablePaymentMethods, forKey: ._summonsAvailablePaymentMethods) +// try container.encode(summonsDisplayFormat, forKey: ._summonsDisplayFormat) +// try container.encode(summonsDisplayEntryFee, forKey: ._summonsDisplayEntryFee) +// try container.encode(summonsUseFullCustomMessage, forKey: ._summonsUseFullCustomMessage) +// +// try container.encode(matchFormatsDefaultDuration, forKey: ._matchFormatsDefaultDuration) +// try container.encode(bracketMatchFormatPreference, forKey: ._bracketMatchFormatPreference) +// try container.encode(groupStageMatchFormatPreference, forKey: ._groupStageMatchFormatPreference) +// try container.encode(loserBracketMatchFormatPreference, forKey: ._loserBracketMatchFormatPreference) +// try container.encode(deviceId, forKey: ._deviceId) +// +// try container.encode(loserBracketMode, forKey: ._loserBracketMode) +// } static func placeHolder() -> CustomUser { return CustomUser(username: "", email: "", firstName: "", lastName: "", phone: nil, country: nil) diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 8991440..538a35c 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -215,14 +215,14 @@ class DataStore: ObservableObject { Guard.main.disconnect() StoreCenter.main.disconnect() - self.user = self._temporaryLocalUser.item ?? CustomUser.placeHolder() - self.user.clubs.removeAll() - // done after because otherwise folders remain for tournament in tournamendIds { StoreCenter.main.destroyStore(identifier: tournament.id) } - + + self.user = self._temporaryLocalUser.item ?? CustomUser.placeHolder() + self.user.clubs.removeAll() + } func copyToLocalServer(tournament: Tournament) { diff --git a/PadelClub/Data/DateInterval.swift b/PadelClub/Data/DateInterval.swift index c6a7a9f..864d9b3 100644 --- a/PadelClub/Data/DateInterval.swift +++ b/PadelClub/Data/DateInterval.swift @@ -10,26 +10,31 @@ import SwiftUI import LeStorage @Observable -final class DateInterval: ModelObject, SyncedStorable { +final class DateInterval: BaseDateInterval { - static func resourceName() -> String { return "date-intervals" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var event: String - var courtIndex: Int - var startDate: Date - var endDate: Date +// static func resourceName() -> String { return "date-intervals" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return false } +// static var relationshipNames: [String] = [] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var event: String +// var courtIndex: Int +// var startDate: Date +// var endDate: Date internal init(event: String, courtIndex: Int, startDate: Date, endDate: Date) { - self.lastUpdate = Date() - self.event = event - self.courtIndex = courtIndex - self.startDate = startDate - self.endDate = endDate + super.init(event: event, courtIndex: courtIndex, startDate: startDate, endDate: endDate) +// self.lastUpdate = Date() +// self.event = event +// self.courtIndex = courtIndex +// self.startDate = startDate +// self.endDate = endDate + } + + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) } var range: Range { @@ -51,14 +56,14 @@ final class DateInterval: ModelObject, SyncedStorable { override func deleteDependencies() { } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _event = "event" - case _courtIndex = "courtIndex" - case _startDate = "startDate" - case _endDate = "endDate" - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _lastUpdate = "lastUpdate" +// case _event = "event" +// case _courtIndex = "courtIndex" +// case _startDate = "startDate" +// case _endDate = "endDate" +// } func insertOnServer() throws { DataStore.shared.dateIntervals.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClub/Data/Event.swift b/PadelClub/Data/Event.swift index 4b6a59f..85df1e4 100644 --- a/PadelClub/Data/Event.swift +++ b/PadelClub/Data/Event.swift @@ -10,29 +10,17 @@ import LeStorage import SwiftUI @Observable -final class Event: ModelObject, SyncedStorable { - - static func resourceName() -> String { return "events" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var creator: String? - var club: String? - var creationDate: Date = Date() - var name: String? - var tenupId: String? +final class Event: BaseEvent { var storeId: String? { return nil } internal init(creator: String? = nil, club: String? = nil, name: String? = nil, tenupId: String? = nil) { - self.lastUpdate = Date() - self.creator = creator - self.club = club - self.name = name - self.tenupId = tenupId + super.init(creator: creator, club: club, name: name, tenupId: tenupId) + + } + + required init(from decoder: Decoder) throws { + try super.init(from: decoder) } override func deleteDependencies() { @@ -108,29 +96,3 @@ final class Event: ModelObject, SyncedStorable { } } - - -extension Event { - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _creator = "creator" - case _club = "club" - case _creationDate = "creationDate" - case _name = "name" - case _tenupId = "tenupId" - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(creator, forKey: ._creator) - try container.encode(club, forKey: ._club) - try container.encode(creationDate, forKey: ._creationDate) - try container.encode(name, forKey: ._name) - try container.encode(tenupId, forKey: ._tenupId) - } - -} diff --git a/PadelClub/Data/Gen/BaseClub.swift b/PadelClub/Data/Gen/BaseClub.swift new file mode 100644 index 0000000..8439123 --- /dev/null +++ b/PadelClub/Data/Gen/BaseClub.swift @@ -0,0 +1,139 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseClub: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "clubs" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var creator: String? = nil + var name: String = "" + var acronym: String = "" + var phone: String? = nil + var code: String? = nil + var address: String? = nil + var city: String? = nil + var zipCode: String? = nil + var latitude: Double? = nil + var longitude: Double? = nil + var courtCount: Int = 2 + var broadcastCode: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + creator: String? = nil, + name: String = "", + acronym: String = "", + phone: String? = nil, + code: String? = nil, + address: String? = nil, + city: String? = nil, + zipCode: String? = nil, + latitude: Double? = nil, + longitude: Double? = nil, + courtCount: Int = 2, + broadcastCode: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.creator = creator + self.name = name + self.acronym = acronym + self.phone = phone + self.code = code + self.address = address + self.city = city + self.zipCode = zipCode + self.latitude = latitude + self.longitude = longitude + self.courtCount = courtCount + self.broadcastCode = broadcastCode + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _creator = "creator" + case _name = "name" + case _acronym = "acronym" + case _phone = "phone" + case _code = "code" + case _address = "address" + case _city = "city" + case _zipCode = "zipCode" + case _latitude = "latitude" + case _longitude = "longitude" + case _courtCount = "courtCount" + case _broadcastCode = "broadcastCode" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? "" + self.acronym = try container.decodeIfPresent(String.self, forKey: ._acronym) ?? "" + self.phone = try container.decodeIfPresent(String.self, forKey: ._phone) ?? nil + self.code = try container.decodeIfPresent(String.self, forKey: ._code) ?? nil + self.address = try container.decodeIfPresent(String.self, forKey: ._address) ?? nil + self.city = try container.decodeIfPresent(String.self, forKey: ._city) ?? nil + self.zipCode = try container.decodeIfPresent(String.self, forKey: ._zipCode) ?? nil + self.latitude = try container.decodeIfPresent(Double.self, forKey: ._latitude) ?? nil + self.longitude = try container.decodeIfPresent(Double.self, forKey: ._longitude) ?? nil + self.courtCount = try container.decodeIfPresent(Int.self, forKey: ._courtCount) ?? 2 + self.broadcastCode = try container.decodeIfPresent(String.self, forKey: ._broadcastCode) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.creator, forKey: ._creator) + try container.encode(self.name, forKey: ._name) + try container.encode(self.acronym, forKey: ._acronym) + try container.encode(self.phone, forKey: ._phone) + try container.encode(self.code, forKey: ._code) + try container.encode(self.address, forKey: ._address) + try container.encode(self.city, forKey: ._city) + try container.encode(self.zipCode, forKey: ._zipCode) + try container.encode(self.latitude, forKey: ._latitude) + try container.encode(self.longitude, forKey: ._longitude) + try container.encode(self.courtCount, forKey: ._courtCount) + try container.encode(self.broadcastCode, forKey: ._broadcastCode) + } + + func creatorValue() -> CustomUser? { + guard let creator = self.creator else { return nil } + return Store.main.findById(creator) + } + + func copy(from other: any Storable) { + guard let club = other as? BaseClub else { return } + self.id = club.id + self.lastUpdate = club.lastUpdate + self.creator = club.creator + self.name = club.name + self.acronym = club.acronym + self.phone = club.phone + self.code = club.code + self.address = club.address + self.city = club.city + self.zipCode = club.zipCode + self.latitude = club.latitude + self.longitude = club.longitude + self.courtCount = club.courtCount + self.broadcastCode = club.broadcastCode + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseCourt.swift b/PadelClub/Data/Gen/BaseCourt.swift new file mode 100644 index 0000000..f3b4f5c --- /dev/null +++ b/PadelClub/Data/Gen/BaseCourt.swift @@ -0,0 +1,89 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseCourt: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "courts" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var index: Int = 0 + var club: String = "" + var name: String? = nil + var exitAllowed: Bool = false + var indoor: Bool = false + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + index: Int = 0, + club: String = "", + name: String? = nil, + exitAllowed: Bool = false, + indoor: Bool = false + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.index = index + self.club = club + self.name = name + self.exitAllowed = exitAllowed + self.indoor = indoor + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _index = "index" + case _club = "club" + case _name = "name" + case _exitAllowed = "exitAllowed" + case _indoor = "indoor" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 + self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? "" + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil + self.exitAllowed = try container.decodeIfPresent(Bool.self, forKey: ._exitAllowed) ?? false + self.indoor = try container.decodeIfPresent(Bool.self, forKey: ._indoor) ?? false + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.index, forKey: ._index) + try container.encode(self.club, forKey: ._club) + try container.encode(self.name, forKey: ._name) + try container.encode(self.exitAllowed, forKey: ._exitAllowed) + try container.encode(self.indoor, forKey: ._indoor) + } + + func clubValue() -> Club? { + return Store.main.findById(club) + } + + func copy(from other: any Storable) { + guard let court = other as? BaseCourt else { return } + self.id = court.id + self.lastUpdate = court.lastUpdate + self.index = court.index + self.club = court.club + self.name = court.name + self.exitAllowed = court.exitAllowed + self.indoor = court.indoor + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseCustomUser.swift b/PadelClub/Data/Gen/BaseCustomUser.swift new file mode 100644 index 0000000..7c5463a --- /dev/null +++ b/PadelClub/Data/Gen/BaseCustomUser.swift @@ -0,0 +1,197 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseCustomUser: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "users" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [.post] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var username: String = "" + var email: String = "" + var clubs: [String] = [] + var umpireCode: String? = nil + var licenceId: String? = nil + var firstName: String = "" + var lastName: String = "" + var phone: String? = nil + var country: String? = nil + var summonsMessageBody: String? = nil + var summonsMessageSignature: String? = nil + var summonsAvailablePaymentMethods: String? = nil + var summonsDisplayFormat: Bool = false + var summonsDisplayEntryFee: Bool = false + var summonsUseFullCustomMessage: Bool = false + var matchFormatsDefaultDuration: [MatchFormat: Int]? = nil + var bracketMatchFormatPreference: MatchFormat? = nil + var groupStageMatchFormatPreference: MatchFormat? = nil + var loserBracketMatchFormatPreference: MatchFormat? = nil + var loserBracketMode: LoserBracketMode = .automatic + var deviceId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + username: String = "", + email: String = "", + clubs: [String] = [], + umpireCode: String? = nil, + licenceId: String? = nil, + firstName: String = "", + lastName: String = "", + phone: String? = nil, + country: String? = nil, + summonsMessageBody: String? = nil, + summonsMessageSignature: String? = nil, + summonsAvailablePaymentMethods: String? = nil, + summonsDisplayFormat: Bool = false, + summonsDisplayEntryFee: Bool = false, + summonsUseFullCustomMessage: Bool = false, + matchFormatsDefaultDuration: [MatchFormat: Int]? = nil, + bracketMatchFormatPreference: MatchFormat? = nil, + groupStageMatchFormatPreference: MatchFormat? = nil, + loserBracketMatchFormatPreference: MatchFormat? = nil, + loserBracketMode: LoserBracketMode = .automatic, + deviceId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.username = username + self.email = email + self.clubs = clubs + self.umpireCode = umpireCode + self.licenceId = licenceId + self.firstName = firstName + self.lastName = lastName + self.phone = phone + self.country = country + self.summonsMessageBody = summonsMessageBody + self.summonsMessageSignature = summonsMessageSignature + self.summonsAvailablePaymentMethods = summonsAvailablePaymentMethods + self.summonsDisplayFormat = summonsDisplayFormat + self.summonsDisplayEntryFee = summonsDisplayEntryFee + self.summonsUseFullCustomMessage = summonsUseFullCustomMessage + self.matchFormatsDefaultDuration = matchFormatsDefaultDuration + self.bracketMatchFormatPreference = bracketMatchFormatPreference + self.groupStageMatchFormatPreference = groupStageMatchFormatPreference + self.loserBracketMatchFormatPreference = loserBracketMatchFormatPreference + self.loserBracketMode = loserBracketMode + self.deviceId = deviceId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _username = "username" + case _email = "email" + case _clubs = "clubs" + case _umpireCode = "umpireCode" + case _licenceId = "licenceId" + case _firstName = "firstName" + case _lastName = "lastName" + case _phone = "phone" + case _country = "country" + case _summonsMessageBody = "summonsMessageBody" + case _summonsMessageSignature = "summonsMessageSignature" + case _summonsAvailablePaymentMethods = "summonsAvailablePaymentMethods" + case _summonsDisplayFormat = "summonsDisplayFormat" + case _summonsDisplayEntryFee = "summonsDisplayEntryFee" + case _summonsUseFullCustomMessage = "summonsUseFullCustomMessage" + case _matchFormatsDefaultDuration = "matchFormatsDefaultDuration" + case _bracketMatchFormatPreference = "bracketMatchFormatPreference" + case _groupStageMatchFormatPreference = "groupStageMatchFormatPreference" + case _loserBracketMatchFormatPreference = "loserBracketMatchFormatPreference" + case _loserBracketMode = "loserBracketMode" + case _deviceId = "deviceId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.username = try container.decodeIfPresent(String.self, forKey: ._username) ?? "" + self.email = try container.decodeIfPresent(String.self, forKey: ._email) ?? "" + self.clubs = try container.decodeIfPresent([String].self, forKey: ._clubs) ?? [] + self.umpireCode = try container.decodeIfPresent(String.self, forKey: ._umpireCode) ?? nil + self.licenceId = try container.decodeIfPresent(String.self, forKey: ._licenceId) ?? nil + self.firstName = try container.decodeIfPresent(String.self, forKey: ._firstName) ?? "" + self.lastName = try container.decodeIfPresent(String.self, forKey: ._lastName) ?? "" + self.phone = try container.decodeIfPresent(String.self, forKey: ._phone) ?? nil + self.country = try container.decodeIfPresent(String.self, forKey: ._country) ?? nil + self.summonsMessageBody = try container.decodeIfPresent(String.self, forKey: ._summonsMessageBody) ?? nil + self.summonsMessageSignature = try container.decodeIfPresent(String.self, forKey: ._summonsMessageSignature) ?? nil + self.summonsAvailablePaymentMethods = try container.decodeIfPresent(String.self, forKey: ._summonsAvailablePaymentMethods) ?? nil + self.summonsDisplayFormat = try container.decodeIfPresent(Bool.self, forKey: ._summonsDisplayFormat) ?? false + self.summonsDisplayEntryFee = try container.decodeIfPresent(Bool.self, forKey: ._summonsDisplayEntryFee) ?? false + self.summonsUseFullCustomMessage = try container.decodeIfPresent(Bool.self, forKey: ._summonsUseFullCustomMessage) ?? false + self.matchFormatsDefaultDuration = try container.decodeIfPresent([MatchFormat: Int].self, forKey: ._matchFormatsDefaultDuration) ?? nil + self.bracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._bracketMatchFormatPreference) ?? nil + self.groupStageMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._groupStageMatchFormatPreference) ?? nil + self.loserBracketMatchFormatPreference = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserBracketMatchFormatPreference) ?? nil + self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic + self.deviceId = try container.decodeIfPresent(String.self, forKey: ._deviceId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.username, forKey: ._username) + try container.encode(self.email, forKey: ._email) + try container.encode(self.clubs, forKey: ._clubs) + try container.encode(self.umpireCode, forKey: ._umpireCode) + try container.encode(self.licenceId, forKey: ._licenceId) + try container.encode(self.firstName, forKey: ._firstName) + try container.encode(self.lastName, forKey: ._lastName) + try container.encode(self.phone, forKey: ._phone) + try container.encode(self.country, forKey: ._country) + try container.encode(self.summonsMessageBody, forKey: ._summonsMessageBody) + try container.encode(self.summonsMessageSignature, forKey: ._summonsMessageSignature) + try container.encode(self.summonsAvailablePaymentMethods, forKey: ._summonsAvailablePaymentMethods) + try container.encode(self.summonsDisplayFormat, forKey: ._summonsDisplayFormat) + try container.encode(self.summonsDisplayEntryFee, forKey: ._summonsDisplayEntryFee) + try container.encode(self.summonsUseFullCustomMessage, forKey: ._summonsUseFullCustomMessage) + try container.encode(self.matchFormatsDefaultDuration, forKey: ._matchFormatsDefaultDuration) + try container.encode(self.bracketMatchFormatPreference, forKey: ._bracketMatchFormatPreference) + try container.encode(self.groupStageMatchFormatPreference, forKey: ._groupStageMatchFormatPreference) + try container.encode(self.loserBracketMatchFormatPreference, forKey: ._loserBracketMatchFormatPreference) + try container.encode(self.loserBracketMode, forKey: ._loserBracketMode) + try container.encode(self.deviceId, forKey: ._deviceId) + } + + func copy(from other: any Storable) { + guard let customuser = other as? BaseCustomUser else { return } + self.id = customuser.id + self.lastUpdate = customuser.lastUpdate + self.username = customuser.username + self.email = customuser.email + self.clubs = customuser.clubs + self.umpireCode = customuser.umpireCode + self.licenceId = customuser.licenceId + self.firstName = customuser.firstName + self.lastName = customuser.lastName + self.phone = customuser.phone + self.country = customuser.country + self.summonsMessageBody = customuser.summonsMessageBody + self.summonsMessageSignature = customuser.summonsMessageSignature + self.summonsAvailablePaymentMethods = customuser.summonsAvailablePaymentMethods + self.summonsDisplayFormat = customuser.summonsDisplayFormat + self.summonsDisplayEntryFee = customuser.summonsDisplayEntryFee + self.summonsUseFullCustomMessage = customuser.summonsUseFullCustomMessage + self.matchFormatsDefaultDuration = customuser.matchFormatsDefaultDuration + self.bracketMatchFormatPreference = customuser.bracketMatchFormatPreference + self.groupStageMatchFormatPreference = customuser.groupStageMatchFormatPreference + self.loserBracketMatchFormatPreference = customuser.loserBracketMatchFormatPreference + self.loserBracketMode = customuser.loserBracketMode + self.deviceId = customuser.deviceId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseDateInterval.swift b/PadelClub/Data/Gen/BaseDateInterval.swift new file mode 100644 index 0000000..1c678f0 --- /dev/null +++ b/PadelClub/Data/Gen/BaseDateInterval.swift @@ -0,0 +1,78 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseDateInterval: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "date-intervals" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var event: String = "" + var courtIndex: Int = 0 + var startDate: Date = Date() + var endDate: Date = Date() + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + event: String = "", + courtIndex: Int = 0, + startDate: Date = Date(), + endDate: Date = Date() + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.event = event + self.courtIndex = courtIndex + self.startDate = startDate + self.endDate = endDate + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _event = "event" + case _courtIndex = "courtIndex" + case _startDate = "startDate" + case _endDate = "endDate" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? "" + self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? 0 + self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date() + self.endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) ?? Date() + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.event, forKey: ._event) + try container.encode(self.courtIndex, forKey: ._courtIndex) + try container.encode(self.startDate, forKey: ._startDate) + try container.encode(self.endDate, forKey: ._endDate) + } + + func copy(from other: any Storable) { + guard let dateinterval = other as? BaseDateInterval else { return } + self.id = dateinterval.id + self.lastUpdate = dateinterval.lastUpdate + self.event = dateinterval.event + self.courtIndex = dateinterval.courtIndex + self.startDate = dateinterval.startDate + self.endDate = dateinterval.endDate + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseEvent.swift b/PadelClub/Data/Gen/BaseEvent.swift new file mode 100644 index 0000000..b184516 --- /dev/null +++ b/PadelClub/Data/Gen/BaseEvent.swift @@ -0,0 +1,95 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseEvent: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "events" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var creator: String? = nil + var club: String? = nil + var creationDate: Date = Date() + var name: String? = nil + var tenupId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + creator: String? = nil, + club: String? = nil, + creationDate: Date = Date(), + name: String? = nil, + tenupId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.creator = creator + self.club = club + self.creationDate = creationDate + self.name = name + self.tenupId = tenupId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _creator = "creator" + case _club = "club" + case _creationDate = "creationDate" + case _name = "name" + case _tenupId = "tenupId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.creator = try container.decodeIfPresent(String.self, forKey: ._creator) ?? nil + self.club = try container.decodeIfPresent(String.self, forKey: ._club) ?? nil + self.creationDate = try container.decodeIfPresent(Date.self, forKey: ._creationDate) ?? Date() + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil + self.tenupId = try container.decodeIfPresent(String.self, forKey: ._tenupId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.creator, forKey: ._creator) + try container.encode(self.club, forKey: ._club) + try container.encode(self.creationDate, forKey: ._creationDate) + try container.encode(self.name, forKey: ._name) + try container.encode(self.tenupId, forKey: ._tenupId) + } + + func creatorValue() -> CustomUser? { + guard let creator = self.creator else { return nil } + return Store.main.findById(creator) + } + + func clubValue() -> Club? { + guard let club = self.club else { return nil } + return Store.main.findById(club) + } + + func copy(from other: any Storable) { + guard let event = other as? BaseEvent else { return } + self.id = event.id + self.lastUpdate = event.lastUpdate + self.creator = event.creator + self.club = event.club + self.creationDate = event.creationDate + self.name = event.name + self.tenupId = event.tenupId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseGroupStage.swift b/PadelClub/Data/Gen/BaseGroupStage.swift new file mode 100644 index 0000000..dd92f1d --- /dev/null +++ b/PadelClub/Data/Gen/BaseGroupStage.swift @@ -0,0 +1,110 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseGroupStage: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "group-stages" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return true } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var tournament: String = "" + var index: Int = 0 + var size: Int = 0 + var format: MatchFormat? = nil + var startDate: Date? = nil + var name: String? = nil + var step: Int = 0 + var storeId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + tournament: String = "", + index: Int = 0, + size: Int = 0, + format: MatchFormat? = nil, + startDate: Date? = nil, + name: String? = nil, + step: Int = 0, + storeId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.tournament = tournament + self.index = index + self.size = size + self.format = format + self.startDate = startDate + self.name = name + self.step = step + self.storeId = storeId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _tournament = "tournament" + case _index = "index" + case _size = "size" + case _format = "format" + case _startDate = "startDate" + case _name = "name" + case _step = "step" + case _storeId = "storeId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? "" + self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 + self.size = try container.decodeIfPresent(Int.self, forKey: ._size) ?? 0 + self.format = try container.decodeIfPresent(MatchFormat.self, forKey: ._format) ?? nil + self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil + self.step = try container.decodeIfPresent(Int.self, forKey: ._step) ?? 0 + self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.tournament, forKey: ._tournament) + try container.encode(self.index, forKey: ._index) + try container.encode(self.size, forKey: ._size) + try container.encode(self.format, forKey: ._format) + try container.encode(self.startDate, forKey: ._startDate) + try container.encode(self.name, forKey: ._name) + try container.encode(self.step, forKey: ._step) + try container.encode(self.storeId, forKey: ._storeId) + } + + func tournamentValue() -> Tournament? { + return Store.main.findById(tournament) + } + + func copy(from other: any Storable) { + guard let groupstage = other as? BaseGroupStage else { return } + self.id = groupstage.id + self.lastUpdate = groupstage.lastUpdate + self.tournament = groupstage.tournament + self.index = groupstage.index + self.size = groupstage.size + self.format = groupstage.format + self.startDate = groupstage.startDate + self.name = groupstage.name + self.step = groupstage.step + self.storeId = groupstage.storeId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseMatch.swift b/PadelClub/Data/Gen/BaseMatch.swift new file mode 100644 index 0000000..eeadae7 --- /dev/null +++ b/PadelClub/Data/Gen/BaseMatch.swift @@ -0,0 +1,158 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseMatch: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "matches" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return true } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var round: String? = nil + var groupStage: String? = nil + var startDate: Date? = nil + var endDate: Date? = nil + var index: Int = 0 + var format: MatchFormat? = nil + var servingTeamId: String? = nil + var winningTeamId: String? = nil + var losingTeamId: String? = nil + var name: String? = nil + var disabled: Bool = false + var courtIndex: Int? = nil + var confirmed: Bool = false + var storeId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + round: String? = nil, + groupStage: String? = nil, + startDate: Date? = nil, + endDate: Date? = nil, + index: Int = 0, + format: MatchFormat? = nil, + servingTeamId: String? = nil, + winningTeamId: String? = nil, + losingTeamId: String? = nil, + name: String? = nil, + disabled: Bool = false, + courtIndex: Int? = nil, + confirmed: Bool = false, + storeId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.round = round + self.groupStage = groupStage + self.startDate = startDate + self.endDate = endDate + self.index = index + self.format = format + self.servingTeamId = servingTeamId + self.winningTeamId = winningTeamId + self.losingTeamId = losingTeamId + self.name = name + self.disabled = disabled + self.courtIndex = courtIndex + self.confirmed = confirmed + self.storeId = storeId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _round = "round" + case _groupStage = "groupStage" + case _startDate = "startDate" + case _endDate = "endDate" + case _index = "index" + case _format = "format" + case _servingTeamId = "servingTeamId" + case _winningTeamId = "winningTeamId" + case _losingTeamId = "losingTeamId" + case _name = "name" + case _disabled = "disabled" + case _courtIndex = "courtIndex" + case _confirmed = "confirmed" + case _storeId = "storeId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.round = try container.decodeIfPresent(String.self, forKey: ._round) ?? nil + self.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? nil + self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil + self.endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) ?? nil + self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 + self.format = try container.decodeIfPresent(MatchFormat.self, forKey: ._format) ?? nil + self.servingTeamId = try container.decodeIfPresent(String.self, forKey: ._servingTeamId) ?? nil + self.winningTeamId = try container.decodeIfPresent(String.self, forKey: ._winningTeamId) ?? nil + self.losingTeamId = try container.decodeIfPresent(String.self, forKey: ._losingTeamId) ?? nil + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil + self.disabled = try container.decodeIfPresent(Bool.self, forKey: ._disabled) ?? false + self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? nil + self.confirmed = try container.decodeIfPresent(Bool.self, forKey: ._confirmed) ?? false + self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.round, forKey: ._round) + try container.encode(self.groupStage, forKey: ._groupStage) + try container.encode(self.startDate, forKey: ._startDate) + try container.encode(self.endDate, forKey: ._endDate) + try container.encode(self.index, forKey: ._index) + try container.encode(self.format, forKey: ._format) + try container.encode(self.servingTeamId, forKey: ._servingTeamId) + try container.encode(self.winningTeamId, forKey: ._winningTeamId) + try container.encode(self.losingTeamId, forKey: ._losingTeamId) + try container.encode(self.name, forKey: ._name) + try container.encode(self.disabled, forKey: ._disabled) + try container.encode(self.courtIndex, forKey: ._courtIndex) + try container.encode(self.confirmed, forKey: ._confirmed) + try container.encode(self.storeId, forKey: ._storeId) + } + + func roundValue() -> Round? { + guard let round = self.round else { return nil } + return self.store?.findById(round) + } + + func groupStageValue() -> GroupStage? { + guard let groupStage = self.groupStage else { return nil } + return self.store?.findById(groupStage) + } + + func copy(from other: any Storable) { + guard let match = other as? BaseMatch else { return } + self.id = match.id + self.lastUpdate = match.lastUpdate + self.round = match.round + self.groupStage = match.groupStage + self.startDate = match.startDate + self.endDate = match.endDate + self.index = match.index + self.format = match.format + self.servingTeamId = match.servingTeamId + self.winningTeamId = match.winningTeamId + self.losingTeamId = match.losingTeamId + self.name = match.name + self.disabled = match.disabled + self.courtIndex = match.courtIndex + self.confirmed = match.confirmed + self.storeId = match.storeId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseMatchScheduler.swift b/PadelClub/Data/Gen/BaseMatchScheduler.swift new file mode 100644 index 0000000..cc962bb --- /dev/null +++ b/PadelClub/Data/Gen/BaseMatchScheduler.swift @@ -0,0 +1,138 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseMatchScheduler: ModelObject, Storable, Codable { + + static func resourceName() -> String { return "match-schedulers" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var tournament: String = "" + var timeDifferenceLimit: Int = 0 + var loserBracketRotationDifference: Int = 0 + var upperBracketRotationDifference: Int = 0 + var accountUpperBracketBreakTime: Bool = false + var accountLoserBracketBreakTime: Bool = false + var randomizeCourts: Bool = false + var rotationDifferenceIsImportant: Bool = false + var shouldHandleUpperRoundSlice: Bool = false + var shouldEndRoundBeforeStartingNext: Bool = false + var groupStageChunkCount: Int? = nil + var overrideCourtsUnavailability: Bool = false + var shouldTryToFillUpCourtsAvailable: Bool = false + + init( + id: String = Store.randomId(), + tournament: String = "", + timeDifferenceLimit: Int = 0, + loserBracketRotationDifference: Int = 0, + upperBracketRotationDifference: Int = 0, + accountUpperBracketBreakTime: Bool = false, + accountLoserBracketBreakTime: Bool = false, + randomizeCourts: Bool = false, + rotationDifferenceIsImportant: Bool = false, + shouldHandleUpperRoundSlice: Bool = false, + shouldEndRoundBeforeStartingNext: Bool = false, + groupStageChunkCount: Int? = nil, + overrideCourtsUnavailability: Bool = false, + shouldTryToFillUpCourtsAvailable: Bool = false + ) { + super.init() + self.id = id + self.tournament = tournament + self.timeDifferenceLimit = timeDifferenceLimit + self.loserBracketRotationDifference = loserBracketRotationDifference + self.upperBracketRotationDifference = upperBracketRotationDifference + self.accountUpperBracketBreakTime = accountUpperBracketBreakTime + self.accountLoserBracketBreakTime = accountLoserBracketBreakTime + self.randomizeCourts = randomizeCourts + self.rotationDifferenceIsImportant = rotationDifferenceIsImportant + self.shouldHandleUpperRoundSlice = shouldHandleUpperRoundSlice + self.shouldEndRoundBeforeStartingNext = shouldEndRoundBeforeStartingNext + self.groupStageChunkCount = groupStageChunkCount + self.overrideCourtsUnavailability = overrideCourtsUnavailability + self.shouldTryToFillUpCourtsAvailable = shouldTryToFillUpCourtsAvailable + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _tournament = "tournament" + case _timeDifferenceLimit = "timeDifferenceLimit" + case _loserBracketRotationDifference = "loserBracketRotationDifference" + case _upperBracketRotationDifference = "upperBracketRotationDifference" + case _accountUpperBracketBreakTime = "accountUpperBracketBreakTime" + case _accountLoserBracketBreakTime = "accountLoserBracketBreakTime" + case _randomizeCourts = "randomizeCourts" + case _rotationDifferenceIsImportant = "rotationDifferenceIsImportant" + case _shouldHandleUpperRoundSlice = "shouldHandleUpperRoundSlice" + case _shouldEndRoundBeforeStartingNext = "shouldEndRoundBeforeStartingNext" + case _groupStageChunkCount = "groupStageChunkCount" + case _overrideCourtsUnavailability = "overrideCourtsUnavailability" + case _shouldTryToFillUpCourtsAvailable = "shouldTryToFillUpCourtsAvailable" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? "" + self.timeDifferenceLimit = try container.decodeIfPresent(Int.self, forKey: ._timeDifferenceLimit) ?? 0 + self.loserBracketRotationDifference = try container.decodeIfPresent(Int.self, forKey: ._loserBracketRotationDifference) ?? 0 + self.upperBracketRotationDifference = try container.decodeIfPresent(Int.self, forKey: ._upperBracketRotationDifference) ?? 0 + self.accountUpperBracketBreakTime = try container.decodeIfPresent(Bool.self, forKey: ._accountUpperBracketBreakTime) ?? false + self.accountLoserBracketBreakTime = try container.decodeIfPresent(Bool.self, forKey: ._accountLoserBracketBreakTime) ?? false + self.randomizeCourts = try container.decodeIfPresent(Bool.self, forKey: ._randomizeCourts) ?? false + self.rotationDifferenceIsImportant = try container.decodeIfPresent(Bool.self, forKey: ._rotationDifferenceIsImportant) ?? false + self.shouldHandleUpperRoundSlice = try container.decodeIfPresent(Bool.self, forKey: ._shouldHandleUpperRoundSlice) ?? false + self.shouldEndRoundBeforeStartingNext = try container.decodeIfPresent(Bool.self, forKey: ._shouldEndRoundBeforeStartingNext) ?? false + self.groupStageChunkCount = try container.decodeIfPresent(Int.self, forKey: ._groupStageChunkCount) ?? nil + self.overrideCourtsUnavailability = try container.decodeIfPresent(Bool.self, forKey: ._overrideCourtsUnavailability) ?? false + self.shouldTryToFillUpCourtsAvailable = try container.decodeIfPresent(Bool.self, forKey: ._shouldTryToFillUpCourtsAvailable) ?? false + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.tournament, forKey: ._tournament) + try container.encode(self.timeDifferenceLimit, forKey: ._timeDifferenceLimit) + try container.encode(self.loserBracketRotationDifference, forKey: ._loserBracketRotationDifference) + try container.encode(self.upperBracketRotationDifference, forKey: ._upperBracketRotationDifference) + try container.encode(self.accountUpperBracketBreakTime, forKey: ._accountUpperBracketBreakTime) + try container.encode(self.accountLoserBracketBreakTime, forKey: ._accountLoserBracketBreakTime) + try container.encode(self.randomizeCourts, forKey: ._randomizeCourts) + try container.encode(self.rotationDifferenceIsImportant, forKey: ._rotationDifferenceIsImportant) + try container.encode(self.shouldHandleUpperRoundSlice, forKey: ._shouldHandleUpperRoundSlice) + try container.encode(self.shouldEndRoundBeforeStartingNext, forKey: ._shouldEndRoundBeforeStartingNext) + try container.encode(self.groupStageChunkCount, forKey: ._groupStageChunkCount) + try container.encode(self.overrideCourtsUnavailability, forKey: ._overrideCourtsUnavailability) + try container.encode(self.shouldTryToFillUpCourtsAvailable, forKey: ._shouldTryToFillUpCourtsAvailable) + } + + func tournamentValue() -> Tournament? { + return Store.main.findById(tournament) + } + + func copy(from other: any Storable) { + guard let matchscheduler = other as? BaseMatchScheduler else { return } + self.id = matchscheduler.id + self.tournament = matchscheduler.tournament + self.timeDifferenceLimit = matchscheduler.timeDifferenceLimit + self.loserBracketRotationDifference = matchscheduler.loserBracketRotationDifference + self.upperBracketRotationDifference = matchscheduler.upperBracketRotationDifference + self.accountUpperBracketBreakTime = matchscheduler.accountUpperBracketBreakTime + self.accountLoserBracketBreakTime = matchscheduler.accountLoserBracketBreakTime + self.randomizeCourts = matchscheduler.randomizeCourts + self.rotationDifferenceIsImportant = matchscheduler.rotationDifferenceIsImportant + self.shouldHandleUpperRoundSlice = matchscheduler.shouldHandleUpperRoundSlice + self.shouldEndRoundBeforeStartingNext = matchscheduler.shouldEndRoundBeforeStartingNext + self.groupStageChunkCount = matchscheduler.groupStageChunkCount + self.overrideCourtsUnavailability = matchscheduler.overrideCourtsUnavailability + self.shouldTryToFillUpCourtsAvailable = matchscheduler.shouldTryToFillUpCourtsAvailable + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseMonthData.swift b/PadelClub/Data/Gen/BaseMonthData.swift new file mode 100644 index 0000000..691529a --- /dev/null +++ b/PadelClub/Data/Gen/BaseMonthData.swift @@ -0,0 +1,113 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseMonthData: ModelObject, Storable, Codable { + + static func resourceName() -> String { return "month-datas" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var monthKey: String = "" + var creationDate: Date = Date() + var maleUnrankedValue: Int? = nil + var femaleUnrankedValue: Int? = nil + var maleCount: Int? = nil + var femaleCount: Int? = nil + var anonymousCount: Int? = nil + var incompleteMode: Bool = false + var dataModelIdentifier: String? = nil + var fileModelIdentifier: String? = nil + + init( + id: String = Store.randomId(), + monthKey: String = "", + creationDate: Date = Date(), + maleUnrankedValue: Int? = nil, + femaleUnrankedValue: Int? = nil, + maleCount: Int? = nil, + femaleCount: Int? = nil, + anonymousCount: Int? = nil, + incompleteMode: Bool = false, + dataModelIdentifier: String? = nil, + fileModelIdentifier: String? = nil + ) { + super.init() + self.id = id + self.monthKey = monthKey + self.creationDate = creationDate + self.maleUnrankedValue = maleUnrankedValue + self.femaleUnrankedValue = femaleUnrankedValue + self.maleCount = maleCount + self.femaleCount = femaleCount + self.anonymousCount = anonymousCount + self.incompleteMode = incompleteMode + self.dataModelIdentifier = dataModelIdentifier + self.fileModelIdentifier = fileModelIdentifier + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _monthKey = "monthKey" + case _creationDate = "creationDate" + case _maleUnrankedValue = "maleUnrankedValue" + case _femaleUnrankedValue = "femaleUnrankedValue" + case _maleCount = "maleCount" + case _femaleCount = "femaleCount" + case _anonymousCount = "anonymousCount" + case _incompleteMode = "incompleteMode" + case _dataModelIdentifier = "dataModelIdentifier" + case _fileModelIdentifier = "fileModelIdentifier" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.monthKey = try container.decodeIfPresent(String.self, forKey: ._monthKey) ?? "" + self.creationDate = try container.decodeIfPresent(Date.self, forKey: ._creationDate) ?? Date() + self.maleUnrankedValue = try container.decodeIfPresent(Int.self, forKey: ._maleUnrankedValue) ?? nil + self.femaleUnrankedValue = try container.decodeIfPresent(Int.self, forKey: ._femaleUnrankedValue) ?? nil + self.maleCount = try container.decodeIfPresent(Int.self, forKey: ._maleCount) ?? nil + self.femaleCount = try container.decodeIfPresent(Int.self, forKey: ._femaleCount) ?? nil + self.anonymousCount = try container.decodeIfPresent(Int.self, forKey: ._anonymousCount) ?? nil + self.incompleteMode = try container.decodeIfPresent(Bool.self, forKey: ._incompleteMode) ?? false + self.dataModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._dataModelIdentifier) ?? nil + self.fileModelIdentifier = try container.decodeIfPresent(String.self, forKey: ._fileModelIdentifier) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.monthKey, forKey: ._monthKey) + try container.encode(self.creationDate, forKey: ._creationDate) + try container.encode(self.maleUnrankedValue, forKey: ._maleUnrankedValue) + try container.encode(self.femaleUnrankedValue, forKey: ._femaleUnrankedValue) + try container.encode(self.maleCount, forKey: ._maleCount) + try container.encode(self.femaleCount, forKey: ._femaleCount) + try container.encode(self.anonymousCount, forKey: ._anonymousCount) + try container.encode(self.incompleteMode, forKey: ._incompleteMode) + try container.encode(self.dataModelIdentifier, forKey: ._dataModelIdentifier) + try container.encode(self.fileModelIdentifier, forKey: ._fileModelIdentifier) + } + + func copy(from other: any Storable) { + guard let monthdata = other as? BaseMonthData else { return } + self.id = monthdata.id + self.monthKey = monthdata.monthKey + self.creationDate = monthdata.creationDate + self.maleUnrankedValue = monthdata.maleUnrankedValue + self.femaleUnrankedValue = monthdata.femaleUnrankedValue + self.maleCount = monthdata.maleCount + self.femaleCount = monthdata.femaleCount + self.anonymousCount = monthdata.anonymousCount + self.incompleteMode = monthdata.incompleteMode + self.dataModelIdentifier = monthdata.dataModelIdentifier + self.fileModelIdentifier = monthdata.fileModelIdentifier + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BasePlayerRegistration.swift b/PadelClub/Data/Gen/BasePlayerRegistration.swift new file mode 100644 index 0000000..4b146da --- /dev/null +++ b/PadelClub/Data/Gen/BasePlayerRegistration.swift @@ -0,0 +1,188 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BasePlayerRegistration: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "player-registrations" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return true } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var teamRegistration: String? = nil + var firstName: String = "" + var lastName: String = "" + var licenceId: String? = nil + var rank: Int? = nil + var paymentType: PlayerPaymentType? = nil + var sex: PlayerSexType? = nil + var tournamentPlayed: Int? = nil + var points: Double? = nil + var clubName: String? = nil + var ligueName: String? = nil + var assimilation: String? = nil + var phoneNumber: String? = nil + var email: String? = nil + var birthdate: String? = nil + var computedRank: Int = 0 + var source: PlayerDataSource? = nil + var hasArrived: Bool = false + var storeId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + teamRegistration: String? = nil, + firstName: String = "", + lastName: String = "", + licenceId: String? = nil, + rank: Int? = nil, + paymentType: PlayerPaymentType? = nil, + sex: PlayerSexType? = nil, + tournamentPlayed: Int? = nil, + points: Double? = nil, + clubName: String? = nil, + ligueName: String? = nil, + assimilation: String? = nil, + phoneNumber: String? = nil, + email: String? = nil, + birthdate: String? = nil, + computedRank: Int = 0, + source: PlayerDataSource? = nil, + hasArrived: Bool = false, + storeId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.teamRegistration = teamRegistration + self.firstName = firstName + self.lastName = lastName + self.licenceId = licenceId + self.rank = rank + self.paymentType = paymentType + self.sex = sex + self.tournamentPlayed = tournamentPlayed + self.points = points + self.clubName = clubName + self.ligueName = ligueName + self.assimilation = assimilation + self.phoneNumber = phoneNumber + self.email = email + self.birthdate = birthdate + self.computedRank = computedRank + self.source = source + self.hasArrived = hasArrived + self.storeId = storeId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _teamRegistration = "teamRegistration" + case _firstName = "firstName" + case _lastName = "lastName" + case _licenceId = "licenceId" + case _rank = "rank" + case _paymentType = "paymentType" + case _sex = "sex" + case _tournamentPlayed = "tournamentPlayed" + case _points = "points" + case _clubName = "clubName" + case _ligueName = "ligueName" + case _assimilation = "assimilation" + case _phoneNumber = "phoneNumber" + case _email = "email" + case _birthdate = "birthdate" + case _computedRank = "computedRank" + case _source = "source" + case _hasArrived = "hasArrived" + case _storeId = "storeId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? nil + self.firstName = try container.decodeIfPresent(String.self, forKey: ._firstName) ?? "" + self.lastName = try container.decodeIfPresent(String.self, forKey: ._lastName) ?? "" + self.licenceId = try container.decodeIfPresent(String.self, forKey: ._licenceId) ?? nil + self.rank = try container.decodeIfPresent(Int.self, forKey: ._rank) ?? nil + self.paymentType = try container.decodeIfPresent(PlayerPaymentType.self, forKey: ._paymentType) ?? nil + self.sex = try container.decodeIfPresent(PlayerSexType.self, forKey: ._sex) ?? nil + self.tournamentPlayed = try container.decodeIfPresent(Int.self, forKey: ._tournamentPlayed) ?? nil + self.points = try container.decodeIfPresent(Double.self, forKey: ._points) ?? nil + self.clubName = try container.decodeIfPresent(String.self, forKey: ._clubName) ?? nil + self.ligueName = try container.decodeIfPresent(String.self, forKey: ._ligueName) ?? nil + self.assimilation = try container.decodeIfPresent(String.self, forKey: ._assimilation) ?? nil + self.phoneNumber = try container.decodeIfPresent(String.self, forKey: ._phoneNumber) ?? nil + self.email = try container.decodeIfPresent(String.self, forKey: ._email) ?? nil + self.birthdate = try container.decodeIfPresent(String.self, forKey: ._birthdate) ?? nil + self.computedRank = try container.decodeIfPresent(Int.self, forKey: ._computedRank) ?? 0 + self.source = try container.decodeIfPresent(PlayerDataSource.self, forKey: ._source) ?? nil + self.hasArrived = try container.decodeIfPresent(Bool.self, forKey: ._hasArrived) ?? false + self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.teamRegistration, forKey: ._teamRegistration) + try container.encode(self.firstName, forKey: ._firstName) + try container.encode(self.lastName, forKey: ._lastName) + try container.encode(self.licenceId, forKey: ._licenceId) + try container.encode(self.rank, forKey: ._rank) + try container.encode(self.paymentType, forKey: ._paymentType) + try container.encode(self.sex, forKey: ._sex) + try container.encode(self.tournamentPlayed, forKey: ._tournamentPlayed) + try container.encode(self.points, forKey: ._points) + try container.encode(self.clubName, forKey: ._clubName) + try container.encode(self.ligueName, forKey: ._ligueName) + try container.encode(self.assimilation, forKey: ._assimilation) + try container.encode(self.phoneNumber, forKey: ._phoneNumber) + try container.encode(self.email, forKey: ._email) + try container.encode(self.birthdate, forKey: ._birthdate) + try container.encode(self.computedRank, forKey: ._computedRank) + try container.encode(self.source, forKey: ._source) + try container.encode(self.hasArrived, forKey: ._hasArrived) + try container.encode(self.storeId, forKey: ._storeId) + } + + func teamRegistrationValue() -> TeamRegistration? { + guard let teamRegistration = self.teamRegistration else { return nil } + return Store.main.findById(teamRegistration) + } + + func copy(from other: any Storable) { + guard let playerregistration = other as? BasePlayerRegistration else { return } + self.id = playerregistration.id + self.lastUpdate = playerregistration.lastUpdate + self.teamRegistration = playerregistration.teamRegistration + self.firstName = playerregistration.firstName + self.lastName = playerregistration.lastName + self.licenceId = playerregistration.licenceId + self.rank = playerregistration.rank + self.paymentType = playerregistration.paymentType + self.sex = playerregistration.sex + self.tournamentPlayed = playerregistration.tournamentPlayed + self.points = playerregistration.points + self.clubName = playerregistration.clubName + self.ligueName = playerregistration.ligueName + self.assimilation = playerregistration.assimilation + self.phoneNumber = playerregistration.phoneNumber + self.email = playerregistration.email + self.birthdate = playerregistration.birthdate + self.computedRank = playerregistration.computedRank + self.source = playerregistration.source + self.hasArrived = playerregistration.hasArrived + self.storeId = playerregistration.storeId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BasePurchase.swift b/PadelClub/Data/Gen/BasePurchase.swift new file mode 100644 index 0000000..4b544dc --- /dev/null +++ b/PadelClub/Data/Gen/BasePurchase.swift @@ -0,0 +1,95 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage + +class BasePurchase: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "purchases" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: UInt64 = 0 + var lastUpdate: Date = Date() + var user: String = "" + var purchaseDate: Date = Date() + var productId: String = "" + var quantity: Int? = nil + var revocationDate: Date? = nil + var expirationDate: Date? = nil + + init( + id: UInt64 = 0, + lastUpdate: Date = Date(), + user: String = "", + purchaseDate: Date = Date(), + productId: String = "", + quantity: Int? = nil, + revocationDate: Date? = nil, + expirationDate: Date? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.user = user + self.purchaseDate = purchaseDate + self.productId = productId + self.quantity = quantity + self.revocationDate = revocationDate + self.expirationDate = expirationDate + } + + enum CodingKeys: String, CodingKey { + case id = "id" + case lastUpdate = "lastUpdate" + case user = "user" + case purchaseDate = "purchaseDate" + case productId = "productId" + case quantity = "quantity" + case revocationDate = "revocationDate" + case expirationDate = "expirationDate" + } + + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(UInt64.self, forKey: .id) ?? 0 + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: .lastUpdate) ?? Date() + self.user = try container.decodeEncrypted(key: .user) + self.purchaseDate = try container.decodeIfPresent(Date.self, forKey: .purchaseDate) ?? Date() + self.productId = try container.decodeIfPresent(String.self, forKey: .productId) ?? "" + self.quantity = try container.decodeIfPresent(Int.self, forKey: .quantity) ?? nil + self.revocationDate = try container.decodeIfPresent(Date.self, forKey: .revocationDate) ?? nil + self.expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: .id) + try container.encode(self.lastUpdate, forKey: .lastUpdate) + try container.encodeAndEncryptIfPresent(self.user.data(using: .utf8), forKey: .user) + try container.encode(self.purchaseDate, forKey: .purchaseDate) + try container.encode(self.productId, forKey: .productId) + try container.encode(self.quantity, forKey: .quantity) + try container.encode(self.revocationDate, forKey: .revocationDate) + try container.encode(self.expirationDate, forKey: .expirationDate) + } + + func userValue() -> CustomUser? { + return Store.main.findById(user) + } + + func copy(from other: any Storable) { + guard let purchase = other as? BasePurchase else { return } + self.id = purchase.id + self.lastUpdate = purchase.lastUpdate + self.user = purchase.user + self.purchaseDate = purchase.purchaseDate + self.productId = purchase.productId + self.quantity = purchase.quantity + self.revocationDate = purchase.revocationDate + self.expirationDate = purchase.expirationDate + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseRound.swift b/PadelClub/Data/Gen/BaseRound.swift new file mode 100644 index 0000000..d0b5402 --- /dev/null +++ b/PadelClub/Data/Gen/BaseRound.swift @@ -0,0 +1,110 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseRound: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "rounds" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return true } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var tournament: String = "" + var index: Int = 0 + var parent: String? = nil + var format: MatchFormat? = nil + var startDate: Date? = nil + var groupStageLoserBracket: Bool = false + var loserBracketMode: LoserBracketMode = .automatic + var storeId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + tournament: String = "", + index: Int = 0, + parent: String? = nil, + format: MatchFormat? = nil, + startDate: Date? = nil, + groupStageLoserBracket: Bool = false, + loserBracketMode: LoserBracketMode = .automatic, + storeId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.tournament = tournament + self.index = index + self.parent = parent + self.format = format + self.startDate = startDate + self.groupStageLoserBracket = groupStageLoserBracket + self.loserBracketMode = loserBracketMode + self.storeId = storeId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _tournament = "tournament" + case _index = "index" + case _parent = "parent" + case _format = "format" + case _startDate = "startDate" + case _groupStageLoserBracket = "groupStageLoserBracket" + case _loserBracketMode = "loserBracketMode" + case _storeId = "storeId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? "" + self.index = try container.decodeIfPresent(Int.self, forKey: ._index) ?? 0 + self.parent = try container.decodeIfPresent(String.self, forKey: ._parent) ?? nil + self.format = try container.decodeIfPresent(MatchFormat.self, forKey: ._format) ?? nil + self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? nil + self.groupStageLoserBracket = try container.decodeIfPresent(Bool.self, forKey: ._groupStageLoserBracket) ?? false + self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic + self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.tournament, forKey: ._tournament) + try container.encode(self.index, forKey: ._index) + try container.encode(self.parent, forKey: ._parent) + try container.encode(self.format, forKey: ._format) + try container.encode(self.startDate, forKey: ._startDate) + try container.encode(self.groupStageLoserBracket, forKey: ._groupStageLoserBracket) + try container.encode(self.loserBracketMode, forKey: ._loserBracketMode) + try container.encode(self.storeId, forKey: ._storeId) + } + + func tournamentValue() -> Tournament? { + return Store.main.findById(tournament) + } + + func copy(from other: any Storable) { + guard let round = other as? BaseRound else { return } + self.id = round.id + self.lastUpdate = round.lastUpdate + self.tournament = round.tournament + self.index = round.index + self.parent = round.parent + self.format = round.format + self.startDate = round.startDate + self.groupStageLoserBracket = round.groupStageLoserBracket + self.loserBracketMode = round.loserBracketMode + self.storeId = round.storeId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseTeamRegistration.swift b/PadelClub/Data/Gen/BaseTeamRegistration.swift new file mode 100644 index 0000000..007ef8d --- /dev/null +++ b/PadelClub/Data/Gen/BaseTeamRegistration.swift @@ -0,0 +1,202 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseTeamRegistration: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "team-registrations" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return true } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var tournament: String = "" + var groupStage: String? = nil + var registrationDate: Date? = nil + var callDate: Date? = nil + var bracketPosition: Int? = nil + var groupStagePosition: Int? = nil + var comment: String? = nil + var source: String? = nil + var sourceValue: String? = nil + var logo: String? = nil + var name: String? = nil + var walkOut: Bool = false + var wildCardBracket: Bool = false + var wildCardGroupStage: Bool = false + var weight: Int = 0 + var lockedWeight: Int? = nil + var confirmationDate: Date? = nil + var qualified: Bool = false + var finalRanking: Int? = nil + var pointsEarned: Int? = nil + var storeId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + tournament: String = "", + groupStage: String? = nil, + registrationDate: Date? = nil, + callDate: Date? = nil, + bracketPosition: Int? = nil, + groupStagePosition: Int? = nil, + comment: String? = nil, + source: String? = nil, + sourceValue: String? = nil, + logo: String? = nil, + name: String? = nil, + walkOut: Bool = false, + wildCardBracket: Bool = false, + wildCardGroupStage: Bool = false, + weight: Int = 0, + lockedWeight: Int? = nil, + confirmationDate: Date? = nil, + qualified: Bool = false, + finalRanking: Int? = nil, + pointsEarned: Int? = nil, + storeId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.tournament = tournament + self.groupStage = groupStage + self.registrationDate = registrationDate + self.callDate = callDate + self.bracketPosition = bracketPosition + self.groupStagePosition = groupStagePosition + self.comment = comment + self.source = source + self.sourceValue = sourceValue + self.logo = logo + self.name = name + self.walkOut = walkOut + self.wildCardBracket = wildCardBracket + self.wildCardGroupStage = wildCardGroupStage + self.weight = weight + self.lockedWeight = lockedWeight + self.confirmationDate = confirmationDate + self.qualified = qualified + self.finalRanking = finalRanking + self.pointsEarned = pointsEarned + self.storeId = storeId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _tournament = "tournament" + case _groupStage = "groupStage" + case _registrationDate = "registrationDate" + case _callDate = "callDate" + case _bracketPosition = "bracketPosition" + case _groupStagePosition = "groupStagePosition" + case _comment = "comment" + case _source = "source" + case _sourceValue = "sourceValue" + case _logo = "logo" + case _name = "name" + case _walkOut = "walkOut" + case _wildCardBracket = "wildCardBracket" + case _wildCardGroupStage = "wildCardGroupStage" + case _weight = "weight" + case _lockedWeight = "lockedWeight" + case _confirmationDate = "confirmationDate" + case _qualified = "qualified" + case _finalRanking = "finalRanking" + case _pointsEarned = "pointsEarned" + case _storeId = "storeId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.tournament = try container.decodeIfPresent(String.self, forKey: ._tournament) ?? "" + self.groupStage = try container.decodeIfPresent(String.self, forKey: ._groupStage) ?? nil + self.registrationDate = try container.decodeIfPresent(Date.self, forKey: ._registrationDate) ?? nil + self.callDate = try container.decodeIfPresent(Date.self, forKey: ._callDate) ?? nil + self.bracketPosition = try container.decodeIfPresent(Int.self, forKey: ._bracketPosition) ?? nil + self.groupStagePosition = try container.decodeIfPresent(Int.self, forKey: ._groupStagePosition) ?? nil + self.comment = try container.decodeIfPresent(String.self, forKey: ._comment) ?? nil + self.source = try container.decodeIfPresent(String.self, forKey: ._source) ?? nil + self.sourceValue = try container.decodeIfPresent(String.self, forKey: ._sourceValue) ?? nil + self.logo = try container.decodeIfPresent(String.self, forKey: ._logo) ?? nil + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil + self.walkOut = try container.decodeIfPresent(Bool.self, forKey: ._walkOut) ?? false + self.wildCardBracket = try container.decodeIfPresent(Bool.self, forKey: ._wildCardBracket) ?? false + self.wildCardGroupStage = try container.decodeIfPresent(Bool.self, forKey: ._wildCardGroupStage) ?? false + self.weight = try container.decodeIfPresent(Int.self, forKey: ._weight) ?? 0 + self.lockedWeight = try container.decodeIfPresent(Int.self, forKey: ._lockedWeight) ?? nil + self.confirmationDate = try container.decodeIfPresent(Date.self, forKey: ._confirmationDate) ?? nil + self.qualified = try container.decodeIfPresent(Bool.self, forKey: ._qualified) ?? false + self.finalRanking = try container.decodeIfPresent(Int.self, forKey: ._finalRanking) ?? nil + self.pointsEarned = try container.decodeIfPresent(Int.self, forKey: ._pointsEarned) ?? nil + self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.tournament, forKey: ._tournament) + try container.encode(self.groupStage, forKey: ._groupStage) + try container.encode(self.registrationDate, forKey: ._registrationDate) + try container.encode(self.callDate, forKey: ._callDate) + try container.encode(self.bracketPosition, forKey: ._bracketPosition) + try container.encode(self.groupStagePosition, forKey: ._groupStagePosition) + try container.encode(self.comment, forKey: ._comment) + try container.encode(self.source, forKey: ._source) + try container.encode(self.sourceValue, forKey: ._sourceValue) + try container.encode(self.logo, forKey: ._logo) + try container.encode(self.name, forKey: ._name) + try container.encode(self.walkOut, forKey: ._walkOut) + try container.encode(self.wildCardBracket, forKey: ._wildCardBracket) + try container.encode(self.wildCardGroupStage, forKey: ._wildCardGroupStage) + try container.encode(self.weight, forKey: ._weight) + try container.encode(self.lockedWeight, forKey: ._lockedWeight) + try container.encode(self.confirmationDate, forKey: ._confirmationDate) + try container.encode(self.qualified, forKey: ._qualified) + try container.encode(self.finalRanking, forKey: ._finalRanking) + try container.encode(self.pointsEarned, forKey: ._pointsEarned) + try container.encode(self.storeId, forKey: ._storeId) + } + + func groupStageValue() -> GroupStage? { + guard let groupStage = self.groupStage else { return nil } + return self.store?.findById(groupStage) + } + + func copy(from other: any Storable) { + guard let teamregistration = other as? BaseTeamRegistration else { return } + self.id = teamregistration.id + self.lastUpdate = teamregistration.lastUpdate + self.tournament = teamregistration.tournament + self.groupStage = teamregistration.groupStage + self.registrationDate = teamregistration.registrationDate + self.callDate = teamregistration.callDate + self.bracketPosition = teamregistration.bracketPosition + self.groupStagePosition = teamregistration.groupStagePosition + self.comment = teamregistration.comment + self.source = teamregistration.source + self.sourceValue = teamregistration.sourceValue + self.logo = teamregistration.logo + self.name = teamregistration.name + self.walkOut = teamregistration.walkOut + self.wildCardBracket = teamregistration.wildCardBracket + self.wildCardGroupStage = teamregistration.wildCardGroupStage + self.weight = teamregistration.weight + self.lockedWeight = teamregistration.lockedWeight + self.confirmationDate = teamregistration.confirmationDate + self.qualified = teamregistration.qualified + self.finalRanking = teamregistration.finalRanking + self.pointsEarned = teamregistration.pointsEarned + self.storeId = teamregistration.storeId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseTeamScore.swift b/PadelClub/Data/Gen/BaseTeamScore.swift new file mode 100644 index 0000000..b4c415f --- /dev/null +++ b/PadelClub/Data/Gen/BaseTeamScore.swift @@ -0,0 +1,101 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseTeamScore: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "team-scores" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return true } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var match: String = "" + var teamRegistration: String? = nil + var score: String? = nil + var walkOut: Int? = nil + var luckyLoser: Int? = nil + var storeId: String? = nil + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + match: String = "", + teamRegistration: String? = nil, + score: String? = nil, + walkOut: Int? = nil, + luckyLoser: Int? = nil, + storeId: String? = nil + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.match = match + self.teamRegistration = teamRegistration + self.score = score + self.walkOut = walkOut + self.luckyLoser = luckyLoser + self.storeId = storeId + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _match = "match" + case _teamRegistration = "teamRegistration" + case _score = "score" + case _walkOut = "walkOut" + case _luckyLoser = "luckyLoser" + case _storeId = "storeId" + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.match = try container.decodeIfPresent(String.self, forKey: ._match) ?? "" + self.teamRegistration = try container.decodeIfPresent(String.self, forKey: ._teamRegistration) ?? nil + self.score = try container.decodeIfPresent(String.self, forKey: ._score) ?? nil + self.walkOut = try container.decodeIfPresent(Int.self, forKey: ._walkOut) ?? nil + self.luckyLoser = try container.decodeIfPresent(Int.self, forKey: ._luckyLoser) ?? nil + self.storeId = try container.decodeIfPresent(String.self, forKey: ._storeId) ?? nil + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.match, forKey: ._match) + try container.encode(self.teamRegistration, forKey: ._teamRegistration) + try container.encode(self.score, forKey: ._score) + try container.encode(self.walkOut, forKey: ._walkOut) + try container.encode(self.luckyLoser, forKey: ._luckyLoser) + try container.encode(self.storeId, forKey: ._storeId) + } + + func matchValue() -> Match? { + return self.store?.findById(match) + } + + func teamRegistrationValue() -> TeamRegistration? { + guard let teamRegistration = self.teamRegistration else { return nil } + return self.store?.findById(teamRegistration) + } + + func copy(from other: any Storable) { + guard let teamscore = other as? BaseTeamScore else { return } + self.id = teamscore.id + self.lastUpdate = teamscore.lastUpdate + self.match = teamscore.match + self.teamRegistration = teamscore.teamRegistration + self.score = teamscore.score + self.walkOut = teamscore.walkOut + self.luckyLoser = teamscore.luckyLoser + self.storeId = teamscore.storeId + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/BaseTournament.swift b/PadelClub/Data/Gen/BaseTournament.swift new file mode 100644 index 0000000..ed5b100 --- /dev/null +++ b/PadelClub/Data/Gen/BaseTournament.swift @@ -0,0 +1,396 @@ +// Generated by SwiftModelGenerator +// Do not modify this file manually + +import Foundation +import LeStorage +import SwiftUI + +@Observable +class BaseTournament: ModelObject, SyncedStorable, Codable { + + static func resourceName() -> String { return "tournaments" } + static func tokenExemptedMethods() -> [HTTPMethod] { return [] } + static func filterByStoreIdentifier() -> Bool { return false } + + var id: String = Store.randomId() + var lastUpdate: Date = Date() + var event: String? = nil + var name: String? = nil + var startDate: Date = Date() + var endDate: Date? = nil + var creationDate: Date = Date() + var isPrivate: Bool = false + var groupStageFormat: MatchFormat? = nil + var roundFormat: MatchFormat? = nil + var loserRoundFormat: MatchFormat? = nil + var groupStageSortMode: GroupStageOrderingMode = GroupStageOrderingMode.snake + var groupStageCount: Int = 0 + var rankSourceDate: Date? = nil + var dayDuration: Int = 0 + var teamCount: Int = 0 + var teamSorting: TeamSortingType = TeamSortingType.inscriptionDate + var federalCategory: TournamentCategory = TournamentCategory.men + var federalLevelCategory: TournamentLevel = TournamentLevel.unlisted + var federalAgeCategory: FederalTournamentAge = FederalTournamentAge.unlisted + var closedRegistrationDate: Date? = nil + var groupStageAdditionalQualified: Int = 0 + var courtCount: Int = 2 + var prioritizeClubMembers: Bool = false + var qualifiedPerGroupStage: Int = 0 + var teamsPerGroupStage: Int = 0 + var entryFee: Double? = nil + var payment: TournamentPayment? = nil + var additionalEstimationDuration: Int = 0 + var isDeleted: Bool = false + var isCanceled: Bool = false + var publishTeams: Bool = false + var publishSummons: Bool = false + var publishGroupStages: Bool = false + var publishBrackets: Bool = false + var shouldVerifyGroupStage: Bool = false + var shouldVerifyBracket: Bool = false + var hideTeamsWeight: Bool = false + var publishTournament: Bool = false + var hidePointsEarned: Bool = false + var publishRankings: Bool = false + var loserBracketMode: LoserBracketMode = .automatic + + init( + id: String = Store.randomId(), + lastUpdate: Date = Date(), + event: String? = nil, + name: String? = nil, + startDate: Date = Date(), + endDate: Date? = nil, + creationDate: Date = Date(), + isPrivate: Bool = false, + groupStageFormat: MatchFormat? = nil, + roundFormat: MatchFormat? = nil, + loserRoundFormat: MatchFormat? = nil, + groupStageSortMode: GroupStageOrderingMode = GroupStageOrderingMode.snake, + groupStageCount: Int = 0, + rankSourceDate: Date? = nil, + dayDuration: Int = 0, + teamCount: Int = 0, + teamSorting: TeamSortingType = TeamSortingType.inscriptionDate, + federalCategory: TournamentCategory = TournamentCategory.men, + federalLevelCategory: TournamentLevel = TournamentLevel.unlisted, + federalAgeCategory: FederalTournamentAge = FederalTournamentAge.unlisted, + closedRegistrationDate: Date? = nil, + groupStageAdditionalQualified: Int = 0, + courtCount: Int = 2, + prioritizeClubMembers: Bool = false, + qualifiedPerGroupStage: Int = 0, + teamsPerGroupStage: Int = 0, + entryFee: Double? = nil, + payment: TournamentPayment? = nil, + additionalEstimationDuration: Int = 0, + isDeleted: Bool = false, + isCanceled: Bool = false, + publishTeams: Bool = false, + publishSummons: Bool = false, + publishGroupStages: Bool = false, + publishBrackets: Bool = false, + shouldVerifyGroupStage: Bool = false, + shouldVerifyBracket: Bool = false, + hideTeamsWeight: Bool = false, + publishTournament: Bool = false, + hidePointsEarned: Bool = false, + publishRankings: Bool = false, + loserBracketMode: LoserBracketMode = .automatic + ) { + super.init() + self.id = id + self.lastUpdate = lastUpdate + self.event = event + self.name = name + self.startDate = startDate + self.endDate = endDate + self.creationDate = creationDate + self.isPrivate = isPrivate + self.groupStageFormat = groupStageFormat + self.roundFormat = roundFormat + self.loserRoundFormat = loserRoundFormat + self.groupStageSortMode = groupStageSortMode + self.groupStageCount = groupStageCount + self.rankSourceDate = rankSourceDate + self.dayDuration = dayDuration + self.teamCount = teamCount + self.teamSorting = teamSorting + self.federalCategory = federalCategory + self.federalLevelCategory = federalLevelCategory + self.federalAgeCategory = federalAgeCategory + self.closedRegistrationDate = closedRegistrationDate + self.groupStageAdditionalQualified = groupStageAdditionalQualified + self.courtCount = courtCount + self.prioritizeClubMembers = prioritizeClubMembers + self.qualifiedPerGroupStage = qualifiedPerGroupStage + self.teamsPerGroupStage = teamsPerGroupStage + self.entryFee = entryFee + self.payment = payment + self.additionalEstimationDuration = additionalEstimationDuration + self.isDeleted = isDeleted + self.isCanceled = isCanceled + self.publishTeams = publishTeams + self.publishSummons = publishSummons + self.publishGroupStages = publishGroupStages + self.publishBrackets = publishBrackets + self.shouldVerifyGroupStage = shouldVerifyGroupStage + self.shouldVerifyBracket = shouldVerifyBracket + self.hideTeamsWeight = hideTeamsWeight + self.publishTournament = publishTournament + self.hidePointsEarned = hidePointsEarned + self.publishRankings = publishRankings + self.loserBracketMode = loserBracketMode + } + + enum CodingKeys: String, CodingKey { + case _id = "id" + case _lastUpdate = "lastUpdate" + case _event = "event" + case _name = "name" + case _startDate = "startDate" + case _endDate = "endDate" + case _creationDate = "creationDate" + case _isPrivate = "isPrivate" + case _groupStageFormat = "groupStageFormat" + case _roundFormat = "roundFormat" + case _loserRoundFormat = "loserRoundFormat" + case _groupStageSortMode = "groupStageSortMode" + case _groupStageCount = "groupStageCount" + case _rankSourceDate = "rankSourceDate" + case _dayDuration = "dayDuration" + case _teamCount = "teamCount" + case _teamSorting = "teamSorting" + case _federalCategory = "federalCategory" + case _federalLevelCategory = "federalLevelCategory" + case _federalAgeCategory = "federalAgeCategory" + case _closedRegistrationDate = "closedRegistrationDate" + case _groupStageAdditionalQualified = "groupStageAdditionalQualified" + case _courtCount = "courtCount" + case _prioritizeClubMembers = "prioritizeClubMembers" + case _qualifiedPerGroupStage = "qualifiedPerGroupStage" + case _teamsPerGroupStage = "teamsPerGroupStage" + case _entryFee = "entryFee" + case _payment = "payment" + case _additionalEstimationDuration = "additionalEstimationDuration" + case _isDeleted = "isDeleted" + case _isCanceled = "isCanceled" + case _publishTeams = "publishTeams" + case _publishSummons = "publishSummons" + case _publishGroupStages = "publishGroupStages" + case _publishBrackets = "publishBrackets" + case _shouldVerifyGroupStage = "shouldVerifyGroupStage" + case _shouldVerifyBracket = "shouldVerifyBracket" + case _hideTeamsWeight = "hideTeamsWeight" + case _publishTournament = "publishTournament" + case _hidePointsEarned = "hidePointsEarned" + case _publishRankings = "publishRankings" + case _loserBracketMode = "loserBracketMode" + } + + private static func _decodePayment(container: KeyedDecodingContainer) throws -> TournamentPayment? { + let data = try container.decodeIfPresent(Data.self, forKey: ._payment) + + if let data { + do { + let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue) + let sequence = decoded.compactMap { NumberFormatter.standard.number(from: String($0))?.intValue } + return TournamentPayment(rawValue: sequence[18]) + } catch { + Logger.error(error) + } + } + return nil + } + + private func _encodePayment(container: inout KeyedEncodingContainer) throws { + guard let payment else { + try container.encodeNil(forKey: ._payment) + return + } + + let max: Int = TournamentPayment.allCases.count + var sequence = (1...18).map { _ in Int.random(in: (0..) throws -> Bool { + let data = try container.decodeIfPresent(Data.self, forKey: ._isCanceled) + if let data { + do { + let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue) + let sequence = decoded.compactMap { NumberFormatter.standard.number(from: String($0))?.intValue } + return Bool.decodeInt(sequence[18]) + } catch { + Logger.error(error) + } + } + return false + } + + private func _encodeIscanceled(container: inout KeyedEncodingContainer) throws { + let max: Int = 9 + var sequence = (1...18).map { _ in Int.random(in: (0...max)) } + sequence.append(self.isCanceled.encodedValue) + sequence.append(contentsOf: (1...13).map { _ in Int.random(in: (0...max ))} ) + + let stringCombo: [String] = sequence.map { $0.formatted() } + let joined: String = stringCombo.joined(separator: "") + if let data = joined.data(using: .utf8) { + let encryped: Data = try data.encrypt(pass: CryptoKey.pass.rawValue) + try container.encode(encryped, forKey: ._isCanceled) + } + } + + required init(from decoder: Decoder) throws { + super.init() + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decodeIfPresent(String.self, forKey: ._id) ?? Store.randomId() + self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: ._lastUpdate) ?? Date() + self.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? nil + self.name = try container.decodeIfPresent(String.self, forKey: ._name) ?? nil + self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date() + self.endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) ?? nil + self.creationDate = try container.decodeIfPresent(Date.self, forKey: ._creationDate) ?? Date() + self.isPrivate = try container.decodeIfPresent(Bool.self, forKey: ._isPrivate) ?? false + self.groupStageFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._groupStageFormat) ?? nil + self.roundFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._roundFormat) ?? nil + self.loserRoundFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserRoundFormat) ?? nil + self.groupStageSortMode = try container.decodeIfPresent(GroupStageOrderingMode.self, forKey: ._groupStageSortMode) ?? GroupStageOrderingMode.snake + self.groupStageCount = try container.decodeIfPresent(Int.self, forKey: ._groupStageCount) ?? 0 + self.rankSourceDate = try container.decodeIfPresent(Date.self, forKey: ._rankSourceDate) ?? nil + self.dayDuration = try container.decodeIfPresent(Int.self, forKey: ._dayDuration) ?? 0 + self.teamCount = try container.decodeIfPresent(Int.self, forKey: ._teamCount) ?? 0 + self.teamSorting = try container.decodeIfPresent(TeamSortingType.self, forKey: ._teamSorting) ?? TeamSortingType.inscriptionDate + self.federalCategory = try container.decodeIfPresent(TournamentCategory.self, forKey: ._federalCategory) ?? TournamentCategory.men + self.federalLevelCategory = try container.decodeIfPresent(TournamentLevel.self, forKey: ._federalLevelCategory) ?? TournamentLevel.unlisted + self.federalAgeCategory = try container.decodeIfPresent(FederalTournamentAge.self, forKey: ._federalAgeCategory) ?? FederalTournamentAge.unlisted + self.closedRegistrationDate = try container.decodeIfPresent(Date.self, forKey: ._closedRegistrationDate) ?? nil + self.groupStageAdditionalQualified = try container.decodeIfPresent(Int.self, forKey: ._groupStageAdditionalQualified) ?? 0 + self.courtCount = try container.decodeIfPresent(Int.self, forKey: ._courtCount) ?? 2 + self.prioritizeClubMembers = try container.decodeIfPresent(Bool.self, forKey: ._prioritizeClubMembers) ?? false + self.qualifiedPerGroupStage = try container.decodeIfPresent(Int.self, forKey: ._qualifiedPerGroupStage) ?? 0 + self.teamsPerGroupStage = try container.decodeIfPresent(Int.self, forKey: ._teamsPerGroupStage) ?? 0 + self.entryFee = try container.decodeIfPresent(Double.self, forKey: ._entryFee) ?? nil + self.payment = try Self._decodePayment(container: container) + self.additionalEstimationDuration = try container.decodeIfPresent(Int.self, forKey: ._additionalEstimationDuration) ?? 0 + self.isDeleted = try container.decodeIfPresent(Bool.self, forKey: ._isDeleted) ?? false + self.isCanceled = try Self._decodeIscanceled(container: container) + self.publishTeams = try container.decodeIfPresent(Bool.self, forKey: ._publishTeams) ?? false + self.publishSummons = try container.decodeIfPresent(Bool.self, forKey: ._publishSummons) ?? false + self.publishGroupStages = try container.decodeIfPresent(Bool.self, forKey: ._publishGroupStages) ?? false + self.publishBrackets = try container.decodeIfPresent(Bool.self, forKey: ._publishBrackets) ?? false + self.shouldVerifyGroupStage = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyGroupStage) ?? false + self.shouldVerifyBracket = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyBracket) ?? false + self.hideTeamsWeight = try container.decodeIfPresent(Bool.self, forKey: ._hideTeamsWeight) ?? false + self.publishTournament = try container.decodeIfPresent(Bool.self, forKey: ._publishTournament) ?? false + self.hidePointsEarned = try container.decodeIfPresent(Bool.self, forKey: ._hidePointsEarned) ?? false + self.publishRankings = try container.decodeIfPresent(Bool.self, forKey: ._publishRankings) ?? false + self.loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.id, forKey: ._id) + try container.encode(self.lastUpdate, forKey: ._lastUpdate) + try container.encode(self.event, forKey: ._event) + try container.encode(self.name, forKey: ._name) + try container.encode(self.startDate, forKey: ._startDate) + try container.encode(self.endDate, forKey: ._endDate) + try container.encode(self.creationDate, forKey: ._creationDate) + try container.encode(self.isPrivate, forKey: ._isPrivate) + try container.encode(self.groupStageFormat, forKey: ._groupStageFormat) + try container.encode(self.roundFormat, forKey: ._roundFormat) + try container.encode(self.loserRoundFormat, forKey: ._loserRoundFormat) + try container.encode(self.groupStageSortMode, forKey: ._groupStageSortMode) + try container.encode(self.groupStageCount, forKey: ._groupStageCount) + try container.encode(self.rankSourceDate, forKey: ._rankSourceDate) + try container.encode(self.dayDuration, forKey: ._dayDuration) + try container.encode(self.teamCount, forKey: ._teamCount) + try container.encode(self.teamSorting, forKey: ._teamSorting) + try container.encode(self.federalCategory, forKey: ._federalCategory) + try container.encode(self.federalLevelCategory, forKey: ._federalLevelCategory) + try container.encode(self.federalAgeCategory, forKey: ._federalAgeCategory) + try container.encode(self.closedRegistrationDate, forKey: ._closedRegistrationDate) + try container.encode(self.groupStageAdditionalQualified, forKey: ._groupStageAdditionalQualified) + try container.encode(self.courtCount, forKey: ._courtCount) + try container.encode(self.prioritizeClubMembers, forKey: ._prioritizeClubMembers) + try container.encode(self.qualifiedPerGroupStage, forKey: ._qualifiedPerGroupStage) + try container.encode(self.teamsPerGroupStage, forKey: ._teamsPerGroupStage) + try container.encode(self.entryFee, forKey: ._entryFee) + try _encodePayment(container: &container) + try container.encode(self.additionalEstimationDuration, forKey: ._additionalEstimationDuration) + try container.encode(self.isDeleted, forKey: ._isDeleted) + try _encodeIscanceled(container: &container) + try container.encode(self.publishTeams, forKey: ._publishTeams) + try container.encode(self.publishSummons, forKey: ._publishSummons) + try container.encode(self.publishGroupStages, forKey: ._publishGroupStages) + try container.encode(self.publishBrackets, forKey: ._publishBrackets) + try container.encode(self.shouldVerifyGroupStage, forKey: ._shouldVerifyGroupStage) + try container.encode(self.shouldVerifyBracket, forKey: ._shouldVerifyBracket) + try container.encode(self.hideTeamsWeight, forKey: ._hideTeamsWeight) + try container.encode(self.publishTournament, forKey: ._publishTournament) + try container.encode(self.hidePointsEarned, forKey: ._hidePointsEarned) + try container.encode(self.publishRankings, forKey: ._publishRankings) + try container.encode(self.loserBracketMode, forKey: ._loserBracketMode) + } + + func eventValue() -> Event? { + guard let event = self.event else { return nil } + return Store.main.findById(event) + } + + func copy(from other: any Storable) { + guard let tournament = other as? BaseTournament else { return } + self.id = tournament.id + self.lastUpdate = tournament.lastUpdate + self.event = tournament.event + self.name = tournament.name + self.startDate = tournament.startDate + self.endDate = tournament.endDate + self.creationDate = tournament.creationDate + self.isPrivate = tournament.isPrivate + self.groupStageFormat = tournament.groupStageFormat + self.roundFormat = tournament.roundFormat + self.loserRoundFormat = tournament.loserRoundFormat + self.groupStageSortMode = tournament.groupStageSortMode + self.groupStageCount = tournament.groupStageCount + self.rankSourceDate = tournament.rankSourceDate + self.dayDuration = tournament.dayDuration + self.teamCount = tournament.teamCount + self.teamSorting = tournament.teamSorting + self.federalCategory = tournament.federalCategory + self.federalLevelCategory = tournament.federalLevelCategory + self.federalAgeCategory = tournament.federalAgeCategory + self.closedRegistrationDate = tournament.closedRegistrationDate + self.groupStageAdditionalQualified = tournament.groupStageAdditionalQualified + self.courtCount = tournament.courtCount + self.prioritizeClubMembers = tournament.prioritizeClubMembers + self.qualifiedPerGroupStage = tournament.qualifiedPerGroupStage + self.teamsPerGroupStage = tournament.teamsPerGroupStage + self.entryFee = tournament.entryFee + self.payment = tournament.payment + self.additionalEstimationDuration = tournament.additionalEstimationDuration + self.isDeleted = tournament.isDeleted + self.isCanceled = tournament.isCanceled + self.publishTeams = tournament.publishTeams + self.publishSummons = tournament.publishSummons + self.publishGroupStages = tournament.publishGroupStages + self.publishBrackets = tournament.publishBrackets + self.shouldVerifyGroupStage = tournament.shouldVerifyGroupStage + self.shouldVerifyBracket = tournament.shouldVerifyBracket + self.hideTeamsWeight = tournament.hideTeamsWeight + self.publishTournament = tournament.publishTournament + self.hidePointsEarned = tournament.hidePointsEarned + self.publishRankings = tournament.publishRankings + self.loserBracketMode = tournament.loserBracketMode + } +} \ No newline at end of file diff --git a/PadelClub/Data/Gen/Club.json b/PadelClub/Data/Gen/Club.json new file mode 100644 index 0000000..683e716 --- /dev/null +++ b/PadelClub/Data/Gen/Club.json @@ -0,0 +1,90 @@ +{ + "models": [ + { + "name": "Club", + "synchronizable": true, + "observable": true, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "creator", + "type": "String", + "optional": true, + "defaultValue": "nil", + "foreignKey": "CustomUser" + }, + { + "name": "name", + "type": "String", + "defaultValue": "\"\"" + }, + { + "name": "acronym", + "type": "String", + "defaultValue": "\"\"" + }, + { + "name": "phone", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "code", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "address", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "city", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "zipCode", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "latitude", + "type": "Double", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "longitude", + "type": "Double", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "courtCount", + "type": "Int", + "defaultValue": "2" + }, + { + "name": "broadcastCode", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/Court.json b/PadelClub/Data/Gen/Court.json new file mode 100644 index 0000000..f2037bb --- /dev/null +++ b/PadelClub/Data/Gen/Court.json @@ -0,0 +1,47 @@ +{ + "models": [ + { + "name": "Court", + "synchronizable": true, + "observable": true, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "index", + "type": "Int" + }, + { + "name": "club", + "type": "String", + "foreignKey": "Club" + }, + { + "name": "name", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "exitAllowed", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "indoor", + "type": "Bool", + "defaultValue": "false" + } + ], + "tokenExemptedMethods": [], + "filterByStoreIdentifier": false + } + ] +} diff --git a/PadelClub/Data/Gen/CustomUser.json b/PadelClub/Data/Gen/CustomUser.json new file mode 100644 index 0000000..b7e3595 --- /dev/null +++ b/PadelClub/Data/Gen/CustomUser.json @@ -0,0 +1,136 @@ +{ + "models": [ + { + "name": "CustomUser", + "resource_name": "users", + "synchronizable": true, + "observable": true, + "tokenExemptedMethods": ["post"], + "filterByStoreIdentifier": false, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "username", + "type": "String" + }, + { + "name": "email", + "type": "String" + }, + { + "name": "clubs", + "type": "[String]", + "defaultValue": "[]" + }, + { + "name": "umpireCode", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "licenceId", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "firstName", + "type": "String" + }, + { + "name": "lastName", + "type": "String" + }, + { + "name": "phone", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "country", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "summonsMessageBody", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "summonsMessageSignature", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "summonsAvailablePaymentMethods", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "summonsDisplayFormat", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "summonsDisplayEntryFee", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "summonsUseFullCustomMessage", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "matchFormatsDefaultDuration", + "type": "[MatchFormat: Int]", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "bracketMatchFormatPreference", + "type": "MatchFormat", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "groupStageMatchFormatPreference", + "type": "MatchFormat", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "loserBracketMatchFormatPreference", + "type": "MatchFormat", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "loserBracketMode", + "type": "LoserBracketMode", + "defaultValue": ".automatic" + }, + { + "name": "deviceId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/DateInterval.json b/PadelClub/Data/Gen/DateInterval.json new file mode 100644 index 0000000..e046b16 --- /dev/null +++ b/PadelClub/Data/Gen/DateInterval.json @@ -0,0 +1,38 @@ +{ + "models": [ + { + "name": "DateInterval", + "synchronizable": true, + "observable": true, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "event", + "type": "String" + }, + { + "name": "courtIndex", + "type": "Int" + }, + { + "name": "startDate", + "type": "Date" + }, + { + "name": "endDate", + "type": "Date" + } + ], + "tokenExemptedMethods": [], + "filterByStoreIdentifier": false + } + ] +} diff --git a/PadelClub/Data/Gen/Event.json b/PadelClub/Data/Gen/Event.json new file mode 100644 index 0000000..b8f1bec --- /dev/null +++ b/PadelClub/Data/Gen/Event.json @@ -0,0 +1,53 @@ +{ + "models": [ + { + "name": "Event", + "synchronizable": true, + "observable": true, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "creator", + "type": "String", + "optional": true, + "defaultValue": "nil", + "foreignKey": "CustomUser" + }, + { + "name": "club", + "type": "String", + "optional": true, + "defaultValue": "nil", + "foreignKey": "Club" + }, + { + "name": "creationDate", + "type": "Date", + "defaultValue": "Date()" + }, + { + "name": "name", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "tenupId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ], + "tokenExemptedMethods": [], + "filterByStoreIdentifier": false + } + ] +} diff --git a/PadelClub/Data/Gen/GroupStage.json b/PadelClub/Data/Gen/GroupStage.json new file mode 100644 index 0000000..eb0627e --- /dev/null +++ b/PadelClub/Data/Gen/GroupStage.json @@ -0,0 +1,64 @@ +{ + "models": [ + { + "name": "GroupStage", + "synchronizable": true, + "observable": true, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "tournament", + "type": "String", + "foreignKey": "Tournament" + }, + { + "name": "index", + "type": "Int" + }, + { + "name": "size", + "type": "Int" + }, + { + "name": "format", + "type": "MatchFormat", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "startDate", + "type": "Date", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "name", + "type": "String", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "step", + "type": "Int", + "defaultValue": "0" + }, + { + "name": "storeId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ], + "tokenExemptedMethods": [], + "filterByStoreIdentifier": true + } + ] +} diff --git a/PadelClub/Data/Gen/Match.json b/PadelClub/Data/Gen/Match.json new file mode 100644 index 0000000..ef04e08 --- /dev/null +++ b/PadelClub/Data/Gen/Match.json @@ -0,0 +1,93 @@ +{ + "models": [ + { + "name": "Match", + "synchronizable": true, + "observable": true, + "tokenExemptedMethods": [], + "filterByStoreIdentifier": true, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "round", + "type": "String", + "optional": true, + "foreignKey": "Round*" + }, + { + "name": "groupStage", + "type": "String", + "optional": true, + "foreignKey": "GroupStage*" + }, + { + "name": "startDate", + "type": "Date", + "optional": true + }, + { + "name": "endDate", + "type": "Date", + "optional": true + }, + { + "name": "index", + "type": "Int" + }, + { + "name": "format", + "type": "MatchFormat", + "optional": true + }, + { + "name": "servingTeamId", + "type": "String", + "optional": true + }, + { + "name": "winningTeamId", + "type": "String", + "optional": true + }, + { + "name": "losingTeamId", + "type": "String", + "optional": true + }, + { + "name": "name", + "type": "String", + "optional": true + }, + { + "name": "disabled", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "courtIndex", + "type": "Int", + "optional": true + }, + { + "name": "confirmed", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "storeId", + "type": "String", + "optional": true + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/MatchScheduler.json b/PadelClub/Data/Gen/MatchScheduler.json new file mode 100644 index 0000000..500bc3d --- /dev/null +++ b/PadelClub/Data/Gen/MatchScheduler.json @@ -0,0 +1,75 @@ +{ + "models": [ + { + "name": "MatchScheduler", + "resource_name": "match-scheduler", + "synchronizable": false, + "observable": true, + "tokenExemptedMethods": [], + "filterByStoreIdentifier": false, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "tournament", + "type": "String", + "foreignKey": "Tournament" + }, + { + "name": "timeDifferenceLimit", + "type": "Int" + }, + { + "name": "loserBracketRotationDifference", + "type": "Int" + }, + { + "name": "upperBracketRotationDifference", + "type": "Int" + }, + { + "name": "accountUpperBracketBreakTime", + "type": "Bool" + }, + { + "name": "accountLoserBracketBreakTime", + "type": "Bool" + }, + { + "name": "randomizeCourts", + "type": "Bool" + }, + { + "name": "rotationDifferenceIsImportant", + "type": "Bool" + }, + { + "name": "shouldHandleUpperRoundSlice", + "type": "Bool" + }, + { + "name": "shouldEndRoundBeforeStartingNext", + "type": "Bool" + }, + { + "name": "groupStageChunkCount", + "type": "Int", + "optional": true + }, + { + "name": "overrideCourtsUnavailability", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "shouldTryToFillUpCourtsAvailable", + "type": "Bool", + "defaultValue": "false" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/MonthData.json b/PadelClub/Data/Gen/MonthData.json new file mode 100644 index 0000000..95c4d9b --- /dev/null +++ b/PadelClub/Data/Gen/MonthData.json @@ -0,0 +1,72 @@ +{ + "models": [ + { + "name": "MonthData", + "resource_name": "month-data", + "synchronizable": false, + "observable": true, + "tokenExemptedMethods": [], + "filterByStoreIdentifier": false, + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "monthKey", + "type": "String" + }, + { + "name": "creationDate", + "type": "Date" + }, + { + "name": "maleUnrankedValue", + "type": "Int", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "femaleUnrankedValue", + "type": "Int", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "maleCount", + "type": "Int", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "femaleCount", + "type": "Int", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "anonymousCount", + "type": "Int", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "incompleteMode", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "dataModelIdentifier", + "type": "String", + "optional": true + }, + { + "name": "fileModelIdentifier", + "type": "String", + "optional": true + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/PlayerRegistration.json b/PadelClub/Data/Gen/PlayerRegistration.json new file mode 100644 index 0000000..c457557 --- /dev/null +++ b/PadelClub/Data/Gen/PlayerRegistration.json @@ -0,0 +1,118 @@ +{ + "models": [ + { + "name": "PlayerRegistration", + "synchronizable": true, + "sideStorable": true, + "filterByStoreIdentifier": true, + "observable": true, + "relationshipNames": ["teamRegistration"], + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "teamRegistration", + "type": "String", + "optional": true, + "foreignKey": "TeamRegistration" + }, + { + "name": "firstName", + "type": "String" + }, + { + "name": "lastName", + "type": "String" + }, + { + "name": "licenceId", + "type": "String", + "optional": true + }, + { + "name": "rank", + "type": "Int", + "optional": true + }, + { + "name": "paymentType", + "type": "PlayerPaymentType", + "optional": true + }, + { + "name": "sex", + "type": "PlayerSexType", + "optional": true + }, + { + "name": "tournamentPlayed", + "type": "Int", + "optional": true + }, + { + "name": "points", + "type": "Double", + "optional": true + }, + { + "name": "clubName", + "type": "String", + "optional": true + }, + { + "name": "ligueName", + "type": "String", + "optional": true + }, + { + "name": "assimilation", + "type": "String", + "optional": true + }, + { + "name": "phoneNumber", + "type": "String", + "optional": true + }, + { + "name": "email", + "type": "String", + "optional": true + }, + { + "name": "birthdate", + "type": "String", + "optional": true + }, + { + "name": "computedRank", + "type": "Int", + "defaultValue": "0" + }, + { + "name": "source", + "type": "PlayerDataSource", + "optional": true + }, + { + "name": "hasArrived", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "storeId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/Purchase.json b/PadelClub/Data/Gen/Purchase.json new file mode 100644 index 0000000..660d9a2 --- /dev/null +++ b/PadelClub/Data/Gen/Purchase.json @@ -0,0 +1,56 @@ +{ + "models": [ + { + "name": "Purchase", + "synchronizable": true, + "properties": [ + { + "name": "id", + "type": "UInt64", + "defaultValue": "0" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "user", + "type": "String", + "defaultValue": "\"\"", + "encryption": "standard", + "foreignKey": "CustomUser" + }, + { + "name": "purchaseDate", + "type": "Date" + }, + { + "name": "productId", + "type": "String", + "defaultValue": "\"\"" + }, + { + "name": "quantity", + "type": "Int", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "revocationDate", + "type": "Date", + "optional": true, + "defaultValue": "nil" + }, + { + "name": "expirationDate", + "type": "Date", + "optional": true, + "defaultValue": "nil" + } + ], + "tokenExemptedMethods": [], + "filterByStoreIdentifier": false, + "relationshipNames": [] + } + ] +} diff --git a/PadelClub/Data/Gen/Round.json b/PadelClub/Data/Gen/Round.json new file mode 100644 index 0000000..6004232 --- /dev/null +++ b/PadelClub/Data/Gen/Round.json @@ -0,0 +1,64 @@ +{ + "models": [ + { + "name": "Round", + "synchronizable": true, + "sideStorable": true, + "filterByStoreIdentifier": true, + "observable": true, + "relationshipNames": [], + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "tournament", + "type": "String", + "foreignKey": "Tournament" + }, + { + "name": "index", + "type": "Int" + }, + { + "name": "parent", + "type": "String", + "optional": true + }, + { + "name": "format", + "type": "MatchFormat", + "optional": true, + "private": true + }, + { + "name": "startDate", + "type": "Date", + "optional": true + }, + { + "name": "groupStageLoserBracket", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "loserBracketMode", + "type": "LoserBracketMode", + "defaultValue": ".automatic" + }, + { + "name": "storeId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/TeamRegistration.json b/PadelClub/Data/Gen/TeamRegistration.json new file mode 100644 index 0000000..88ac151 --- /dev/null +++ b/PadelClub/Data/Gen/TeamRegistration.json @@ -0,0 +1,129 @@ +{ + "models": [ + { + "name": "TeamRegistration", + "synchronizable": true, + "sideStorable": true, + "filterByStoreIdentifier": true, + "observable": true, + "relationshipNames": [], + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "tournament", + "type": "String" + }, + { + "name": "groupStage", + "type": "String", + "optional": true, + "foreignKey": "GroupStage*" + }, + { + "name": "registrationDate", + "type": "Date", + "optional": true + }, + { + "name": "callDate", + "type": "Date", + "optional": true + }, + { + "name": "bracketPosition", + "type": "Int", + "optional": true + }, + { + "name": "groupStagePosition", + "type": "Int", + "optional": true + }, + { + "name": "comment", + "type": "String", + "optional": true + }, + { + "name": "source", + "type": "String", + "optional": true + }, + { + "name": "sourceValue", + "type": "String", + "optional": true + }, + { + "name": "logo", + "type": "String", + "optional": true + }, + { + "name": "name", + "type": "String", + "optional": true + }, + { + "name": "walkOut", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "wildCardBracket", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "wildCardGroupStage", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "weight", + "type": "Int", + "defaultValue": "0" + }, + { + "name": "lockedWeight", + "type": "Int", + "optional": true + }, + { + "name": "confirmationDate", + "type": "Date", + "optional": true + }, + { + "name": "qualified", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "finalRanking", + "type": "Int", + "optional": true + }, + { + "name": "pointsEarned", + "type": "Int", + "optional": true + }, + { + "name": "storeId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/TeamScore.json b/PadelClub/Data/Gen/TeamScore.json new file mode 100644 index 0000000..7475164 --- /dev/null +++ b/PadelClub/Data/Gen/TeamScore.json @@ -0,0 +1,55 @@ +{ + "models": [ + { + "name": "TeamScore", + "synchronizable": true, + "sideStorable": true, + "filterByStoreIdentifier": true, + "observable": true, + "relationshipNames": ["match"], + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "match", + "type": "String", + "foreignKey": "Match*" + }, + { + "name": "teamRegistration", + "type": "String", + "optional": true, + "foreignKey": "TeamRegistration*" + }, + { + "name": "score", + "type": "String", + "optional": true + }, + { + "name": "walkOut", + "type": "Int", + "optional": true + }, + { + "name": "luckyLoser", + "type": "Int", + "optional": true + }, + { + "name": "storeId", + "type": "String", + "optional": true, + "defaultValue": "nil" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/Tournament.json b/PadelClub/Data/Gen/Tournament.json new file mode 100644 index 0000000..e5368f9 --- /dev/null +++ b/PadelClub/Data/Gen/Tournament.json @@ -0,0 +1,221 @@ +{ + "models": [ + { + "name": "Tournament", + "synchronizable": true, + "copyable": true, + "filterByStoreIdentifier": false, + "observable": true, + "relationshipNames": [], + "properties": [ + { + "name": "id", + "type": "String", + "defaultValue": "Store.randomId()" + }, + { + "name": "lastUpdate", + "type": "Date" + }, + { + "name": "event", + "type": "String", + "optional": true, + "foreignKey": "Event" + }, + { + "name": "name", + "type": "String", + "optional": true + }, + { + "name": "startDate", + "type": "Date" + }, + { + "name": "endDate", + "type": "Date", + "optional": true + }, + { + "name": "creationDate", + "type": "Date", + "private": true + }, + { + "name": "isPrivate", + "type": "Bool" + }, + { + "name": "groupStageFormat", + "type": "MatchFormat", + "optional": true, + "private": true + }, + { + "name": "roundFormat", + "type": "MatchFormat", + "optional": true, + "private": true + }, + { + "name": "loserRoundFormat", + "type": "MatchFormat", + "optional": true, + "private": true + }, + { + "name": "groupStageSortMode", + "type": "GroupStageOrderingMode", + "defaultValue": "GroupStageOrderingMode.snake" + }, + { + "name": "groupStageCount", + "type": "Int" + }, + { + "name": "rankSourceDate", + "type": "Date", + "optional": true + }, + { + "name": "dayDuration", + "type": "Int" + }, + { + "name": "teamCount", + "type": "Int" + }, + { + "name": "teamSorting", + "type": "TeamSortingType", + "defaultValue": "TeamSortingType.inscriptionDate" + }, + { + "name": "federalCategory", + "type": "TournamentCategory", + "defaultValue": "TournamentCategory.men" + }, + { + "name": "federalLevelCategory", + "type": "TournamentLevel", + "defaultValue": "TournamentLevel.unlisted" + }, + { + "name": "federalAgeCategory", + "type": "FederalTournamentAge", + "defaultValue": "FederalTournamentAge.unlisted" + }, + { + "name": "closedRegistrationDate", + "type": "Date", + "optional": true + }, + { + "name": "groupStageAdditionalQualified", + "type": "Int" + }, + { + "name": "courtCount", + "type": "Int", + "defaultValue": "2" + }, + { + "name": "prioritizeClubMembers", + "type": "Bool" + }, + { + "name": "qualifiedPerGroupStage", + "type": "Int" + }, + { + "name": "teamsPerGroupStage", + "type": "Int" + }, + { + "name": "entryFee", + "type": "Double", + "optional": true + }, + { + "name": "payment", + "type": "TournamentPayment", + "optional": true, + "defaultValue": "nil", + "encryption": "tournament_payment" + }, + { + "name": "additionalEstimationDuration", + "type": "Int", + "defaultValue": "0" + }, + { + "name": "isDeleted", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "isCanceled", + "type": "Bool", + "defaultValue": "false", + "encryption": "tournament_iscanceled" + }, + { + "name": "publishTeams", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "publishSummons", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "publishGroupStages", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "publishBrackets", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "shouldVerifyGroupStage", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "shouldVerifyBracket", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "hideTeamsWeight", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "publishTournament", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "hidePointsEarned", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "publishRankings", + "type": "Bool", + "defaultValue": "false" + }, + { + "name": "loserBracketMode", + "type": "LoserBracketMode", + "defaultValue": ".automatic" + } + ] + } + ] +} diff --git a/PadelClub/Data/Gen/generator.py b/PadelClub/Data/Gen/generator.py new file mode 100644 index 0000000..68cb248 --- /dev/null +++ b/PadelClub/Data/Gen/generator.py @@ -0,0 +1,504 @@ +import json +import re +import os +from pathlib import Path +from typing import Dict, List, Any +import argparse +import sys +import logging +from datetime import datetime +import inflect + +class SwiftModelGenerator: + def __init__(self, json_data: Dict[str, Any]): + self.data = json_data + self.pluralizer = inflect.engine() + + def generate_model(self, model_data: Dict[str, Any]) -> str: + model_name = model_data["name"] + is_sync = model_data.get("synchronizable", False) + is_observable = model_data.get("observable", False) + properties = model_data["properties"] + + # Get protocol specific configurations + resource = self.make_resource_name(model_name) + resource_name = model_data.get("resource_name", resource) + token_exempted = model_data.get("tokenExemptedMethods", []) + filter_by_store = model_data.get("filterByStoreIdentifier", False) + + lines = ["// Generated by SwiftModelGenerator", "// Do not modify this file manually", ""] + + # Import statement + lines.append("import Foundation") + lines.append("import LeStorage") + if is_observable: + lines.append("import SwiftUI") + lines.append("") + + # Class declaration + if is_observable: + lines.append("@Observable") + protocol = "SyncedStorable" if is_sync else "Storable" + lines.append(f"class Base{model_name}: ModelObject, {protocol}, Codable {{") + lines.append("") + + # Add SyncedStorable protocol requirements + lines.extend(self._generate_protocol_requirements(resource_name, token_exempted, filter_by_store)) + lines.append("") + + # Properties + for prop in properties: + swift_type = prop["type"] + if prop.get("optional", False): + swift_type += "?" + default_value = prop.get("defaultValue", "nil" if prop.get("optional", False) else self._get_default_value(swift_type)) + lines.append(f" var {prop['name']}: {swift_type} = {default_value}") + + lines.append("") + + # Add constructor + lines.extend(self._generate_constructor(model_name, properties)) + lines.append("") + + # CodingKeys + lines.extend(self._generate_coding_keys(properties, is_observable)) + lines.append("") + + # Encryption methods + encrypted_props = [p for p in properties if "encryption" in p] + if encrypted_props: + lines.extend(self._generate_encryption_methods(properties)) + lines.append("") + + # Codable implementation + lines.extend(self._generate_decoder(model_name, properties, is_observable)) + lines.append("") + lines.extend(self._generate_encoder(properties, is_observable)) + lines.append("") + + # Foreign Key convenience + foreign_key_methods = self._generate_foreign_key_methods(properties) + if foreign_key_methods: + lines.extend(foreign_key_methods) + # lines.append("") + + # Copy method + lines.extend(self._generate_copy_method(model_name, properties)) + + lines.append("}") + return "\n".join(lines) + + def _generate_constructor(self, model_name: str, properties: List[Dict[str, Any]]) -> List[str]: + """Generate a constructor with all properties as parameters with default values.""" + lines = [" init("] + + # Generate parameter list + params = [] + for prop in properties: + name = prop['name'] + type_name = prop['type'] + is_optional = prop.get("optional", False) + + # Always include a default value + default_value = prop.get("defaultValue") + if default_value is None: + if is_optional: + default_value = "nil" + else: + default_value = self._get_default_value(type_name) + + # Format the parameter with its type and default value + param = f" {name}: {type_name}" + if is_optional: + param += "?" + param += f" = {default_value}" + params.append(param) + + # Join parameters with commas + lines.extend([f"{param}," for param in params[:-1]]) + lines.append(f"{params[-1]}") # Last parameter without comma + + # Constructor body + lines.extend([ + " ) {", + " super.init()", + ]) + + # Property assignments + for prop in properties: + name = prop['name'] + lines.append(f" self.{name} = {name}") + + lines.append(" }") + return lines + + def _generate_foreign_key_methods(self, properties: List[Dict[str, Any]]) -> List[str]: + lines = [] + for prop in properties: + if "foreignKey" in prop: + foreign_key = prop["foreignKey"] + prop_name = prop["name"] + method_name = f"{prop_name}Value" + is_optional = prop.get("optional", False) + + lines.extend([f" func {method_name}() -> {foreign_key.rstrip('*')}? {{"]) + + if is_optional: + lines.extend([ + f" guard let {prop_name} = self.{prop_name} else {{ return nil }}" + ]) + + if foreign_key.endswith("*"): + foreign_key = foreign_key[:-1] # Remove the asterisk + lines.extend([ + f" return self.store?.findById({prop_name})" + ]) + else: + lines.extend([ + f" return Store.main.findById({prop_name})" + ]) + + lines.extend([" }", ""]) # Close the method and add a blank line + return lines + + def _generate_coding_keys(self, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: + lines = [" enum CodingKeys: String, CodingKey {"] + for prop in properties: + name = prop['name'] + # Add underscore prefix to case name if observable, but keep the string value without underscore + case_name = f"_{name}" if is_observable else name + lines.append(f" case {case_name} = \"{name}\"") + lines.append(" }") + return lines + + def _generate_encryption_methods(self, properties: List[Dict[str, Any]]) -> List[str]: + lines = [] + for prop in properties: + if "encryption" in prop: + name = prop['name'] + enc_type = prop['encryption'] + if enc_type == "tournament_payment": + lines.extend([ + f" private static func _decode{name.capitalize()}(container: KeyedDecodingContainer) throws -> TournamentPayment? {{", + f" let data = try container.decodeIfPresent(Data.self, forKey: ._{name})", + " ", + " if let data {", + " do {", + " let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue)", + " let sequence = decoded.compactMap { NumberFormatter.standard.number(from: String($0))?.intValue }", + " return TournamentPayment(rawValue: sequence[18])", + " } catch {", + " Logger.error(error)", + " }", + " }", + " return nil", + " }", + "", + f" private func _encode{name.capitalize()}(container: inout KeyedEncodingContainer) throws {{", + f" guard let {name} else {{", + f" try container.encodeNil(forKey: ._{name})", + " return", + " }", + " ", + " let max: Int = TournamentPayment.allCases.count", + " var sequence = (1...18).map { _ in Int.random(in: (0..) throws -> Bool {{", + f" let data = try container.decodeIfPresent(Data.self, forKey: ._{name})", + " if let data {", + " do {", + " let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue)", + " let sequence = decoded.compactMap { NumberFormatter.standard.number(from: String($0))?.intValue }", + " return Bool.decodeInt(sequence[18])", + " } catch {", + " Logger.error(error)", + " }", + " }", + " return false", + " }", + "", + f" private func _encode{name.capitalize()}(container: inout KeyedEncodingContainer) throws {{", + " let max: Int = 9", + " var sequence = (1...18).map { _ in Int.random(in: (0...max)) }", + f" sequence.append(self.{name}.encodedValue)", + " sequence.append(contentsOf: (1...13).map { _ in Int.random(in: (0...max ))} )", + " ", + " let stringCombo: [String] = sequence.map { $0.formatted() }", + " let joined: String = stringCombo.joined(separator: \"\")", + " if let data = joined.data(using: .utf8) {", + " let encryped: Data = try data.encrypt(pass: CryptoKey.pass.rawValue)", + f" try container.encode(encryped, forKey: ._{name})", + " }", + " }" + ]) + return lines + + def _generate_decoder(self, model_name: str, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: + lines = [" required init(from decoder: Decoder) throws {", + " super.init()", + " let container = try decoder.container(keyedBy: CodingKeys.self)"] + + for prop in properties: + name = prop['name'] + type_name = prop['type'] + is_optional = prop.get("optional", False) + default_value = prop.get("defaultValue", "nil" if is_optional else self._get_default_value(type_name)) + + # Use the correct case reference based on observable flag + case_ref = f"_{name}" if is_observable else name + + if "encryption" in prop: + enc_type = prop['encryption'] + if enc_type == "standard": + if is_optional: + lines.append(f" self.{name} = try container.decodeEncryptedIfPresent(key: .{case_ref})") + else: + lines.append(f" self.{name} = try container.decodeEncrypted(key: .{case_ref})") + elif enc_type in ["tournament_payment", "tournament_iscanceled"]: + lines.append(f" self.{name} = try Self._decode{name.capitalize()}(container: container)") + else: + lines.append(f" self.{name} = try container.decodeIfPresent({type_name}.self, forKey: .{case_ref}) ?? {default_value}") + + lines.append(" }") + return lines + + def _generate_encoder(self, properties: List[Dict[str, Any]], is_observable: bool) -> List[str]: + lines = [" func encode(to encoder: Encoder) throws {", + " var container = encoder.container(keyedBy: CodingKeys.self)"] + + for prop in properties: + name = prop['name'] + is_optional = prop.get('optional', False) + + # Use the correct case reference based on observable flag + case_ref = f"_{name}" if is_observable else name + + if "encryption" in prop: + enc_type = prop['encryption'] + if enc_type == "standard": + if is_optional: + lines.append(f" try container.encodeAndEncryptIfPresent(self.{name}?.data(using: .utf8), forKey: .{case_ref})") + else: + lines.append(f" try container.encodeAndEncryptIfPresent(self.{name}.data(using: .utf8), forKey: .{case_ref})") + elif enc_type in ["tournament_payment", "tournament_iscanceled"]: + lines.append(f" try _encode{name.capitalize()}(container: &container)") + else: + lines.append(f" try container.encode(self.{name}, forKey: .{case_ref})") + + lines.append(" }") + return lines + + def _generate_copy_method(self, model_name: str, properties: List[Dict[str, Any]]) -> List[str]: + + model_variable = model_name.lower() + lines = [f" func copy(from other: any Storable) {{"] + lines.append(f" guard let {model_variable} = other as? Base{model_name} else {{ return }}") + + for prop in properties: + name = prop['name'] + lines.append(f" self.{name} = {model_variable}.{name}") + + lines.append(" }") + return lines + + def _generate_protocol_requirements(self, resource_name: str, token_exempted: List[str], filter_by_store: bool) -> List[str]: + """Generate the static functions required by SyncedStorable protocol.""" + # Convert HTTP methods to proper format + formatted_methods = [f".{method.lower()}" for method in token_exempted] + methods_str = ", ".join(formatted_methods) if formatted_methods else "" + + return [ + f" static func resourceName() -> String {{ return \"{resource_name}\" }}", + f" static func tokenExemptedMethods() -> [HTTPMethod] {{ return [{methods_str}] }}", + f" static func filterByStoreIdentifier() -> Bool {{ return {str(filter_by_store).lower()} }}" + ] + + + def _get_default_value(self, type_name: str) -> str: + """Get default value for non-optional types""" + if "String" in type_name: + return "\"\"" + elif "Int" in type_name: + return "0" + elif "Double" in type_name: + return "0.0" + elif "Bool" in type_name: + return "false" + elif "Date" in type_name: + return "Date()" + else: + return "nil" # For any other type + + def get_output_filename(self, model_name: str) -> str: + """Generate the output filename for a model.""" + return f"Base{model_name}.swift" + + def make_resource_name(self, text): + p = inflect.engine() + # Split camelCase into words + words = re.findall('[A-Z][^A-Z]*', text) + + if not words: + words = [text] + + words = [word.lower() for word in words] + words[-1] = p.plural(words[-1]) + return '-'.join(words) + +def process_directory(input_dir: str, output_dir: str, logger: logging.Logger, dry_run: bool = False) -> int: + """Process all JSON files in the input directory and generate Swift models.""" + try: + input_path = validate_directory(input_dir) + if not dry_run: + output_path = validate_directory(output_dir, create=True) + + json_files = list(input_path.glob("*.json")) + if not json_files: + logger.warning(f"No JSON files found in '{input_dir}'") + return 0 + + logger.info(f"Found {len(json_files)} JSON files to process") + successful_files = 0 + + for json_file in json_files: + try: + with open(json_file, 'r') as f: + json_data = json.load(f) + + generator = SwiftModelGenerator(json_data) + + # Generate each model in the JSON file + for model in json_data["models"]: + model_name = model["name"] + swift_code = generator.generate_model(model) + + if dry_run: + logger.info(f"Would generate Base{model_name}.swift") + continue + + # Write to output file with Base prefix + output_file = output_path / generator.get_output_filename(model_name) + with open(output_file, 'w') as f: + f.write(swift_code) + + logger.info(f"Generated Base{model_name}.swift") + + successful_files += 1 + + except json.JSONDecodeError as e: + logger.error(f"Error parsing {json_file.name}: {e}") + except KeyError as e: + logger.error(f"Missing required key in {json_file.name}: {e}") + except Exception as e: + logger.error(f"Error processing {json_file.name}: {e}") + + return successful_files + + except Exception as e: + logger.error(f"Fatal error: {e}") + return 0 + + +def setup_logging(verbose: bool) -> logging.Logger: + """Configure logging based on verbosity level.""" + logger = logging.getLogger('SwiftModelGenerator') + handler = logging.StreamHandler() + + if verbose: + logger.setLevel(logging.DEBUG) + handler.setFormatter(logging.Formatter( + '%(asctime)s - %(levelname)s - %(message)s' + )) + else: + logger.setLevel(logging.INFO) + handler.setFormatter(logging.Formatter('%(message)s')) + + logger.addHandler(handler) + return logger + +def validate_directory(path: str, create: bool = False) -> Path: + """Validate and optionally create a directory.""" + dir_path = Path(path) + if dir_path.exists(): + if not dir_path.is_dir(): + raise ValueError(f"'{path}' exists but is not a directory") + elif create: + dir_path.mkdir(parents=True) + else: + raise ValueError(f"Directory '{path}' does not exist") + return dir_path + +def main(): + parser = argparse.ArgumentParser( + description="Generate Swift model classes from JSON definitions", + epilog="Example: %(prog)s -i ./model_definitions -o ../MyProject/Models" + ) + + parser.add_argument( + "-i", "--input-dir", + required=True, + help="Directory containing JSON model definitions" + ) + + parser.add_argument( + "-o", "--output-dir", + required=True, + help="Directory where Swift files will be generated" + ) + + parser.add_argument( + "-v", "--verbose", + action="store_true", + help="Enable verbose output" + ) + + parser.add_argument( + "--dry-run", + action="store_true", + help="Show what would be generated without actually creating files" + ) + + parser.add_argument( + "--version", + action="version", + version="%(prog)s 1.0.0" + ) + + args = parser.parse_args() + + # Setup logging + logger = setup_logging(args.verbose) + + # Process the directories + start_time = datetime.now() + logger.info("Starting model generation...") + + successful_files = process_directory( + args.input_dir, + args.output_dir, + logger, + args.dry_run + ) + + # Report results + duration = datetime.now() - start_time + logger.info(f"\nGeneration completed in {duration.total_seconds():.2f} seconds") + logger.info(f"Successfully processed {successful_files} files") + + # Return appropriate exit code + sys.exit(0 if successful_files > 0 else 1) + +if __name__ == "__main__": + main() diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index 740a730..e544016 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -11,22 +11,22 @@ import Algorithms import SwiftUI @Observable -final class GroupStage: ModelObject, SyncedStorable, SideStorable { +final class GroupStage: BaseGroupStage, SideStorable { - static func resourceName() -> String { "group-stages" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return true } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var tournament: String - var index: Int - var size: Int - private var format: MatchFormat? - var startDate: Date? - var name: String? - var step: Int = 0 +// static func resourceName() -> String { "group-stages" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return true } +// static var relationshipNames: [String] = [] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var tournament: String +// var index: Int +// var size: Int +// private(set) var format: MatchFormat? +// var startDate: Date? +// var name: String? +// var step: Int = 0 var matchFormat: MatchFormat { get { @@ -37,17 +37,24 @@ final class GroupStage: ModelObject, SyncedStorable, SideStorable { } } - var storeId: String? = nil +// var storeId: String? = nil internal init(tournament: String, index: Int, size: Int, matchFormat: MatchFormat? = nil, startDate: Date? = nil, name: String? = nil, step: Int = 0) { - self.lastUpdate = Date() - self.tournament = tournament - self.index = index - self.size = size - self.format = matchFormat - self.startDate = startDate - self.name = name - self.step = step + + super.init(tournament: tournament, index: index, size: size, format: matchFormat, startDate: startDate, name: name, step: step) + +// self.lastUpdate = Date() +// self.tournament = tournament +// self.index = index +// self.size = size +// self.format = matchFormat +// self.startDate = startDate +// self.name = name +// self.step = step + } + + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) } var tournamentStore: TournamentStore { @@ -114,7 +121,7 @@ final class GroupStage: ModelObject, SyncedStorable, SideStorable { fileprivate func _createMatch(index: Int) -> Match { let match: Match = Match(groupStage: self.id, index: index, - matchFormat: self.matchFormat, + format: self.matchFormat, name: self.localizedMatchUpLabel(for: index)) match.store = self.store return match @@ -500,34 +507,35 @@ final class GroupStage: ModelObject, SyncedStorable, SideStorable { self.tournamentStore.matches.deleteDependencies(matches) } - init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - id = try container.decode(String.self, forKey: ._id) - lastUpdate = try container.decode(Date.self, forKey: ._lastUpdate) - tournament = try container.decode(String.self, forKey: ._tournament) - index = try container.decode(Int.self, forKey: ._index) - size = try container.decode(Int.self, forKey: ._size) - format = try container.decodeIfPresent(MatchFormat.self, forKey: ._format) - startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) - name = try container.decodeIfPresent(String.self, forKey: ._name) - step = try container.decodeIfPresent(Int.self, forKey: ._step) ?? 0 - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(storeId, forKey: ._storeId) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(tournament, forKey: ._tournament) - try container.encode(index, forKey: ._index) - try container.encode(size, forKey: ._size) - try container.encode(format, forKey: ._format) - try container.encode(startDate, forKey: ._startDate) - try container.encode(name, forKey: ._name) - try container.encode(step, forKey: ._step) - } +// init(from decoder: Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// +// id = try container.decode(String.self, forKey: ._id) +// storeId = try container.decode(String.self, forKey: ._storeId) +// lastUpdate = try container.decode(Date.self, forKey: ._lastUpdate) +// tournament = try container.decode(String.self, forKey: ._tournament) +// index = try container.decode(Int.self, forKey: ._index) +// size = try container.decode(Int.self, forKey: ._size) +// format = try container.decodeIfPresent(MatchFormat.self, forKey: ._format) +// startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) +// name = try container.decodeIfPresent(String.self, forKey: ._name) +// step = try container.decodeIfPresent(Int.self, forKey: ._step) ?? 0 +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(storeId, forKey: ._storeId) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(tournament, forKey: ._tournament) +// try container.encode(index, forKey: ._index) +// try container.encode(size, forKey: ._size) +// try container.encode(format, forKey: ._format) +// try container.encode(startDate, forKey: ._startDate) +// try container.encode(name, forKey: ._name) +// try container.encode(step, forKey: ._step) +// } func insertOnServer() { self.tournamentStore.groupStages.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index f44eb8e..43988ed 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -9,11 +9,12 @@ import Foundation import LeStorage @Observable -final class Match: ModelObject, SyncedStorable, SideStorable { - static func resourceName() -> String { "matches" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return true } - static var relationshipNames: [String] = ["round", "groupStage"] +final class Match: BaseMatch, SideStorable { + +// static func resourceName() -> String { "matches" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return true } +// static var relationshipNames: [String] = ["round", "groupStage"] static func setServerTitle(upperRound: Round, matchIndex: Int) -> String { if upperRound.index == 0 { return upperRound.roundTitle() } @@ -22,45 +23,52 @@ final class Match: ModelObject, SyncedStorable, SideStorable { var byeState: Bool = false - var id: String = Store.randomId() - var lastUpdate: Date - var round: String? - var groupStage: String? - var startDate: Date? - var endDate: Date? - var index: Int - private var format: MatchFormat? - //var court: String? - var servingTeamId: String? - var winningTeamId: String? - var losingTeamId: String? - //var broadcasted: Bool - var name: String? - //var order: Int - var disabled: Bool = false - private(set) var courtIndex: Int? - var confirmed: Bool = false - - var storeId: String? = nil - - init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, matchFormat: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil, name: String? = nil, disabled: Bool = false, courtIndex: Int? = nil, confirmed: Bool = false) { - self.lastUpdate = Date() - self.round = round - self.groupStage = groupStage - self.startDate = startDate - self.endDate = endDate - self.index = index - self.format = matchFormat - //self.court = court - self.servingTeamId = servingTeamId - self.winningTeamId = winningTeamId - self.losingTeamId = losingTeamId - self.disabled = disabled - self.name = name - self.courtIndex = courtIndex - self.confirmed = confirmed -// self.broadcasted = broadcasted -// self.order = order +// var id: String = Store.randomId() +// var lastUpdate: Date +// var round: String? +// var groupStage: String? +// var startDate: Date? +// var endDate: Date? +// var index: Int +// var format: MatchFormat? +// //var court: String? +// var servingTeamId: String? +// var winningTeamId: String? +// var losingTeamId: String? +// //var broadcasted: Bool +// var name: String? +// //var order: Int +// var disabled: Bool = false +// private(set) var courtIndex: Int? +// var confirmed: Bool = false +// +// var storeId: String? = nil + + init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, format: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil, name: String? = nil, disabled: Bool = false, courtIndex: Int? = nil, confirmed: Bool = false) { + + super.init(round: round, groupStage: groupStage, startDate: startDate, endDate: endDate, index: index, format: format, servingTeamId: servingTeamId, winningTeamId: winningTeamId, losingTeamId: losingTeamId, name: name, disabled: disabled, courtIndex: courtIndex, confirmed: confirmed) + +// self.lastUpdate = Date() +// self.round = round +// self.groupStage = groupStage +// self.startDate = startDate +// self.endDate = endDate +// self.index = index +// self.format = matchFormat +// //self.court = court +// self.servingTeamId = servingTeamId +// self.winningTeamId = winningTeamId +// self.losingTeamId = losingTeamId +// self.disabled = disabled +// self.name = name +// self.courtIndex = courtIndex +// self.confirmed = confirmed +//// self.broadcasted = broadcasted +//// self.order = order + } + + required init(from decoder: Decoder) throws { + try super.init(from: decoder) } var tournamentStore: TournamentStore { @@ -816,6 +824,7 @@ defer { var groupStageObject: GroupStage? { guard let groupStage else { return nil } return self.tournamentStore.groupStages.findById(groupStage) +// self.store?.findById(group) } var isLoserBracket: Bool { @@ -837,48 +846,48 @@ defer { } } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _storeId = "storeId" - case _lastUpdate = "lastUpdate" - case _round = "round" - case _groupStage = "groupStage" - case _startDate = "startDate" - case _endDate = "endDate" - case _index = "index" - case _format = "format" -// case _court = "court" - case _courtIndex = "courtIndex" - case _servingTeamId = "servingTeamId" - case _winningTeamId = "winningTeamId" - case _losingTeamId = "losingTeamId" -// case _broadcasted = "broadcasted" - case _name = "name" -// case _order = "order" - case _disabled = "disabled" - case _confirmed = "confirmed" - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(storeId, forKey: ._storeId) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(round, forKey: ._round) - try container.encode(groupStage, forKey: ._groupStage) - try container.encode(startDate, forKey: ._startDate) - try container.encode(endDate, forKey: ._endDate) - try container.encode(format, forKey: ._format) - try container.encode(servingTeamId, forKey: ._servingTeamId) - try container.encode(index, forKey: ._index) - try container.encode(winningTeamId, forKey: ._winningTeamId) - try container.encode(losingTeamId, forKey: ._losingTeamId) - try container.encode(name, forKey: ._name) - try container.encode(disabled, forKey: ._disabled) - try container.encode(courtIndex, forKey: ._courtIndex) - try container.encode(confirmed, forKey: ._confirmed) - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _storeId = "storeId" +// case _lastUpdate = "lastUpdate" +// case _round = "round" +// case _groupStage = "groupStage" +// case _startDate = "startDate" +// case _endDate = "endDate" +// case _index = "index" +// case _format = "format" +//// case _court = "court" +// case _courtIndex = "courtIndex" +// case _servingTeamId = "servingTeamId" +// case _winningTeamId = "winningTeamId" +// case _losingTeamId = "losingTeamId" +//// case _broadcasted = "broadcasted" +// case _name = "name" +//// case _order = "order" +// case _disabled = "disabled" +// case _confirmed = "confirmed" +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(storeId, forKey: ._storeId) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(round, forKey: ._round) +// try container.encode(groupStage, forKey: ._groupStage) +// try container.encode(startDate, forKey: ._startDate) +// try container.encode(endDate, forKey: ._endDate) +// try container.encode(format, forKey: ._format) +// try container.encode(servingTeamId, forKey: ._servingTeamId) +// try container.encode(index, forKey: ._index) +// try container.encode(winningTeamId, forKey: ._winningTeamId) +// try container.encode(losingTeamId, forKey: ._losingTeamId) +// try container.encode(name, forKey: ._name) +// try container.encode(disabled, forKey: ._disabled) +// try container.encode(courtIndex, forKey: ._courtIndex) +// try container.encode(confirmed, forKey: ._confirmed) +// } func insertOnServer() { self.tournamentStore.matches.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClub/Data/MatchScheduler.swift b/PadelClub/Data/MatchScheduler.swift index 2ef29f9..d603864 100644 --- a/PadelClub/Data/MatchScheduler.swift +++ b/PadelClub/Data/MatchScheduler.swift @@ -10,27 +10,27 @@ import LeStorage import SwiftUI @Observable -final class MatchScheduler : ModelObject, Storable { +final class MatchScheduler : BaseMatchScheduler { - static func resourceName() -> String { return "match-scheduler" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - private(set) var id: String = Store.randomId() - var tournament: String - var timeDifferenceLimit: Int - var loserBracketRotationDifference: Int - var upperBracketRotationDifference: Int - var accountUpperBracketBreakTime: Bool - var accountLoserBracketBreakTime: Bool - var randomizeCourts: Bool - var rotationDifferenceIsImportant: Bool - var shouldHandleUpperRoundSlice: Bool - var shouldEndRoundBeforeStartingNext: Bool - var groupStageChunkCount: Int? - var overrideCourtsUnavailability: Bool = false - var shouldTryToFillUpCourtsAvailable: Bool = false +// static func resourceName() -> String { return "match-scheduler" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return false } +// static var relationshipNames: [String] = [] +// +// private(set) var id: String = Store.randomId() +// var tournament: String +// var timeDifferenceLimit: Int +// var loserBracketRotationDifference: Int +// var upperBracketRotationDifference: Int +// var accountUpperBracketBreakTime: Bool +// var accountLoserBracketBreakTime: Bool +// var randomizeCourts: Bool +// var rotationDifferenceIsImportant: Bool +// var shouldHandleUpperRoundSlice: Bool +// var shouldEndRoundBeforeStartingNext: Bool +// var groupStageChunkCount: Int? +// var overrideCourtsUnavailability: Bool = false +// var shouldTryToFillUpCourtsAvailable: Bool = false init(tournament: String, timeDifferenceLimit: Int = 5, @@ -43,6 +43,7 @@ final class MatchScheduler : ModelObject, Storable { shouldHandleUpperRoundSlice: Bool = true, shouldEndRoundBeforeStartingNext: Bool = true, groupStageChunkCount: Int? = nil, overrideCourtsUnavailability: Bool = false, shouldTryToFillUpCourtsAvailable: Bool = false) { + super.init() self.tournament = tournament self.timeDifferenceLimit = timeDifferenceLimit self.loserBracketRotationDifference = loserBracketRotationDifference @@ -58,22 +59,26 @@ final class MatchScheduler : ModelObject, Storable { self.shouldTryToFillUpCourtsAvailable = shouldTryToFillUpCourtsAvailable } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _tournament = "tournament" - case _timeDifferenceLimit = "timeDifferenceLimit" - case _loserBracketRotationDifference = "loserBracketRotationDifference" - case _upperBracketRotationDifference = "upperBracketRotationDifference" - case _accountUpperBracketBreakTime = "accountUpperBracketBreakTime" - case _accountLoserBracketBreakTime = "accountLoserBracketBreakTime" - case _randomizeCourts = "randomizeCourts" - case _rotationDifferenceIsImportant = "rotationDifferenceIsImportant" - case _shouldHandleUpperRoundSlice = "shouldHandleUpperRoundSlice" - case _shouldEndRoundBeforeStartingNext = "shouldEndRoundBeforeStartingNext" - case _groupStageChunkCount = "groupStageChunkCount" - case _overrideCourtsUnavailability = "overrideCourtsUnavailability" - case _shouldTryToFillUpCourtsAvailable = "shouldTryToFillUpCourtsAvailable" + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) } + +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _tournament = "tournament" +// case _timeDifferenceLimit = "timeDifferenceLimit" +// case _loserBracketRotationDifference = "loserBracketRotationDifference" +// case _upperBracketRotationDifference = "upperBracketRotationDifference" +// case _accountUpperBracketBreakTime = "accountUpperBracketBreakTime" +// case _accountLoserBracketBreakTime = "accountLoserBracketBreakTime" +// case _randomizeCourts = "randomizeCourts" +// case _rotationDifferenceIsImportant = "rotationDifferenceIsImportant" +// case _shouldHandleUpperRoundSlice = "shouldHandleUpperRoundSlice" +// case _shouldEndRoundBeforeStartingNext = "shouldEndRoundBeforeStartingNext" +// case _groupStageChunkCount = "groupStageChunkCount" +// case _overrideCourtsUnavailability = "overrideCourtsUnavailability" +// case _shouldTryToFillUpCourtsAvailable = "shouldTryToFillUpCourtsAvailable" +// } var courtsUnavailability: [DateInterval]? { guard let event = tournamentObject()?.eventObject() else { return nil } diff --git a/PadelClub/Data/MonthData.swift b/PadelClub/Data/MonthData.swift index a7a102b..ab49252 100644 --- a/PadelClub/Data/MonthData.swift +++ b/PadelClub/Data/MonthData.swift @@ -88,17 +88,22 @@ final class MonthData: ModelObject, Storable { override func deleteDependencies() { } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _monthKey = "monthKey" - case _creationDate = "creationDate" - case _maleUnrankedValue = "maleUnrankedValue" - case _femaleUnrankedValue = "femaleUnrankedValue" - case _maleCount = "maleCount" - case _femaleCount = "femaleCount" - case _anonymousCount = "anonymousCount" - case _incompleteMode = "incompleteMode" - case _dataModelIdentifier = "dataModelIdentifier" - case _fileModelIdentifier = "fileModelIdentifier" +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _monthKey = "monthKey" +// case _creationDate = "creationDate" +// case _maleUnrankedValue = "maleUnrankedValue" +// case _femaleUnrankedValue = "femaleUnrankedValue" +// case _maleCount = "maleCount" +// case _femaleCount = "femaleCount" +// case _anonymousCount = "anonymousCount" +// case _incompleteMode = "incompleteMode" +// case _dataModelIdentifier = "dataModelIdentifier" +// case _fileModelIdentifier = "fileModelIdentifier" +// } + + func copy(from other: any Storable) { + fatalError("should not happen") } + } diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index ca1afa4..f6ef828 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -9,41 +9,41 @@ import Foundation import LeStorage @Observable -final class PlayerRegistration: ModelObject, SyncedStorable, SideStorable { - static func resourceName() -> String { "player-registrations" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return true } - static var relationshipNames: [String] = ["teamRegistration"] - - var id: String = Store.randomId() - var lastUpdate: Date - var teamRegistration: String? - var firstName: String - var lastName: String - var licenceId: String? - var rank: Int? - var paymentType: PlayerPaymentType? - var sex: PlayerSexType? - - var tournamentPlayed: Int? - var points: Double? - var clubName: String? - var ligueName: String? - var assimilation: String? - - var phoneNumber: String? - var email: String? - var birthdate: String? - - var computedRank: Int = 0 - var source: PlayerDataSource? - - var hasArrived: Bool = false - - var storeId: String? = nil +final class PlayerRegistration: BasePlayerRegistration, SideStorable { +// static func resourceName() -> String { "player-registrations" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return true } +// static var relationshipNames: [String] = ["teamRegistration"] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var teamRegistration: String? +// var firstName: String +// var lastName: String +// var licenceId: String? +// var rank: Int? +// var paymentType: PlayerPaymentType? +// var sex: PlayerSexType? +// +// var tournamentPlayed: Int? +// var points: Double? +// var clubName: String? +// var ligueName: String? +// var assimilation: String? +// +// var phoneNumber: String? +// var email: String? +// var birthdate: String? +// +// var computedRank: Int = 0 +// var source: PlayerDataSource? +// +// var hasArrived: Bool = false +// +// var storeId: String? = nil init(teamRegistration: String? = nil, firstName: String, lastName: String, licenceId: String? = nil, rank: Int? = nil, paymentType: PlayerPaymentType? = nil, sex: PlayerSexType? = nil, tournamentPlayed: Int? = nil, points: Double? = nil, clubName: String? = nil, ligueName: String? = nil, assimilation: String? = nil, phoneNumber: String? = nil, email: String? = nil, birthdate: String? = nil, computedRank: Int = 0, source: PlayerDataSource? = nil, hasArrived: Bool = false) { - self.lastUpdate = Date() + super.init() self.teamRegistration = teamRegistration self.firstName = firstName self.lastName = lastName @@ -65,7 +65,7 @@ final class PlayerRegistration: ModelObject, SyncedStorable, SideStorable { } internal init(importedPlayer: ImportedPlayer) { - self.lastUpdate = Date() + super.init() self.teamRegistration = "" self.firstName = (importedPlayer.firstName ?? "").trimmed.capitalized self.lastName = (importedPlayer.lastName ?? "").trimmed.uppercased() @@ -82,7 +82,7 @@ final class PlayerRegistration: ModelObject, SyncedStorable, SideStorable { } internal init?(federalData: [String], sex: Int, sexUnknown: Bool) { - self.lastUpdate = Date() + super.init() let _lastName = federalData[0].trimmed.uppercased() let _firstName = federalData[1].trimmed.capitalized if _lastName.isEmpty && _firstName.isEmpty { return nil } @@ -120,6 +120,10 @@ final class PlayerRegistration: ModelObject, SyncedStorable, SideStorable { } } + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) + } + var tournamentStore: TournamentStore { if let store = self.store as? TournamentStore { return store @@ -327,120 +331,58 @@ final class PlayerRegistration: ModelObject, SyncedStorable, SideStorable { return false } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _storeId = "storeId" - case _lastUpdate = "lastUpdate" - case _teamRegistration = "teamRegistration" - case _firstName = "firstName" - case _lastName = "lastName" - case _licenceId = "licenceId" - case _rank = "rank" - case _paymentType = "paymentType" - case _sex = "sex" - case _tournamentPlayed = "tournamentPlayed" - case _points = "points" - case _clubName = "clubName" - case _ligueName = "ligueName" - case _assimilation = "assimilation" - case _birthdate = "birthdate" - case _phoneNumber = "phoneNumber" - case _email = "email" - case _computedRank = "computedRank" - case _source = "source" - case _hasArrived = "hasArrived" - - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(storeId, forKey: ._storeId) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(teamRegistration, forKey: ._teamRegistration) - - try container.encode(firstName, forKey: ._firstName) - try container.encode(lastName, forKey: ._lastName) - try container.encode(licenceId, forKey: ._licenceId) - try container.encode(rank, forKey: ._rank) - try container.encode(paymentType, forKey: ._paymentType) - try container.encode(sex, forKey: ._sex) - try container.encode(tournamentPlayed, forKey: ._tournamentPlayed) - try container.encode(points, forKey: ._points) - try container.encode(clubName, forKey: ._clubName) - try container.encode(ligueName, forKey: ._ligueName) - try container.encode(assimilation, forKey: ._assimilation) - try container.encode(phoneNumber, forKey: ._phoneNumber) - try container.encode(email, forKey: ._email) - try container.encode(birthdate, forKey: ._birthdate) - try container.encode(computedRank, forKey: ._computedRank) - try container.encode(source, forKey: ._source) - try container.encode(hasArrived, forKey: ._hasArrived) - } - - enum PlayerDataSource: Int, Codable { - case frenchFederation = 0 - case beachPadel = 1 - } - - enum PlayerSexType: Int, Hashable, CaseIterable, Identifiable, Codable { - init?(rawValue: Int?) { - guard let value = rawValue else { return nil } - self.init(rawValue: value) - } - - var id: Self { - self - } - - case female = 0 - case male = 1 - } - - enum PlayerPaymentType: Int, CaseIterable, Identifiable, Codable { - init?(rawValue: Int?) { - guard let value = rawValue else { return nil } - self.init(rawValue: value) - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _storeId = "storeId" +// case _lastUpdate = "lastUpdate" +// case _teamRegistration = "teamRegistration" +// case _firstName = "firstName" +// case _lastName = "lastName" +// case _licenceId = "licenceId" +// case _rank = "rank" +// case _paymentType = "paymentType" +// case _sex = "sex" +// case _tournamentPlayed = "tournamentPlayed" +// case _points = "points" +// case _clubName = "clubName" +// case _ligueName = "ligueName" +// case _assimilation = "assimilation" +// case _birthdate = "birthdate" +// case _phoneNumber = "phoneNumber" +// case _email = "email" +// case _computedRank = "computedRank" +// case _source = "source" +// case _hasArrived = "hasArrived" +// +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(storeId, forKey: ._storeId) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(teamRegistration, forKey: ._teamRegistration) +// +// try container.encode(firstName, forKey: ._firstName) +// try container.encode(lastName, forKey: ._lastName) +// try container.encode(licenceId, forKey: ._licenceId) +// try container.encode(rank, forKey: ._rank) +// try container.encode(paymentType, forKey: ._paymentType) +// try container.encode(sex, forKey: ._sex) +// try container.encode(tournamentPlayed, forKey: ._tournamentPlayed) +// try container.encode(points, forKey: ._points) +// try container.encode(clubName, forKey: ._clubName) +// try container.encode(ligueName, forKey: ._ligueName) +// try container.encode(assimilation, forKey: ._assimilation) +// try container.encode(phoneNumber, forKey: ._phoneNumber) +// try container.encode(email, forKey: ._email) +// try container.encode(birthdate, forKey: ._birthdate) +// try container.encode(computedRank, forKey: ._computedRank) +// try container.encode(source, forKey: ._source) +// try container.encode(hasArrived, forKey: ._hasArrived) +// } - var id: Self { - self - } - - case cash = 0 - case lydia = 1 - case gift = 2 - case check = 3 - case paylib = 4 - case bankTransfer = 5 - case clubHouse = 6 - case creditCard = 7 - case forfeit = 8 - - func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String { - switch self { - case .check: - return "Chèque" - case .cash: - return "Cash" - case .lydia: - return "Lydia" - case .paylib: - return "Paylib" - case .bankTransfer: - return "Virement" - case .clubHouse: - return "Clubhouse" - case .creditCard: - return "CB" - case .forfeit: - return "Forfait" - case .gift: - return "Offert" - } - } - } static func addon(for playerRank: Int, manMax: Int, womanMax: Int) -> Int { switch playerRank { @@ -514,3 +456,66 @@ extension PlayerRegistration: PlayerHolder { computedRank } } + +enum PlayerDataSource: Int, Codable { + case frenchFederation = 0 + case beachPadel = 1 +} + +enum PlayerSexType: Int, Hashable, CaseIterable, Identifiable, Codable { + init?(rawValue: Int?) { + guard let value = rawValue else { return nil } + self.init(rawValue: value) + } + + var id: Self { + self + } + + case female = 0 + case male = 1 +} + +enum PlayerPaymentType: Int, CaseIterable, Identifiable, Codable { + init?(rawValue: Int?) { + guard let value = rawValue else { return nil } + self.init(rawValue: value) + } + + var id: Self { + self + } + + case cash = 0 + case lydia = 1 + case gift = 2 + case check = 3 + case paylib = 4 + case bankTransfer = 5 + case clubHouse = 6 + case creditCard = 7 + case forfeit = 8 + + func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String { + switch self { + case .check: + return "Chèque" + case .cash: + return "Cash" + case .lydia: + return "Lydia" + case .paylib: + return "Paylib" + case .bankTransfer: + return "Virement" + case .clubHouse: + return "Clubhouse" + case .creditCard: + return "CB" + case .forfeit: + return "Forfait" + case .gift: + return "Offert" + } + } +} diff --git a/PadelClub/Data/Round.swift b/PadelClub/Data/Round.swift index e1e4ed5..957cdac 100644 --- a/PadelClub/Data/Round.swift +++ b/PadelClub/Data/Round.swift @@ -10,34 +10,41 @@ import LeStorage import SwiftUI @Observable -final class Round: ModelObject, SyncedStorable, SideStorable { +final class Round: BaseRound, SideStorable { - static func resourceName() -> String { "rounds" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return true } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var tournament: String - var index: Int - var parent: String? - private(set) var format: MatchFormat? - var startDate: Date? - var groupStageLoserBracket: Bool = false - var loserBracketMode: LoserBracketMode = .automatic - - var storeId: String? = nil +// static func resourceName() -> String { "rounds" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return true } +// static var relationshipNames: [String] = [] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var tournament: String +// var index: Int +// var parent: String? +// private(set) var format: MatchFormat? +// var startDate: Date? +// var groupStageLoserBracket: Bool = false +// var loserBracketMode: LoserBracketMode = .automatic +// +// var storeId: String? = nil internal init(tournament: String, index: Int, parent: String? = nil, matchFormat: MatchFormat? = nil, startDate: Date? = nil, groupStageLoserBracket: Bool = false, loserBracketMode: LoserBracketMode = .automatic) { - self.lastUpdate = Date() - self.tournament = tournament - self.index = index - self.parent = parent - self.format = matchFormat - self.startDate = startDate - self.groupStageLoserBracket = groupStageLoserBracket - self.loserBracketMode = loserBracketMode + + super.init(tournament: tournament, index: index, parent: parent, format: matchFormat, startDate: startDate, groupStageLoserBracket: groupStageLoserBracket, loserBracketMode: loserBracketMode) + +// self.lastUpdate = Date() +// self.tournament = tournament +// self.index = index +// self.parent = parent +// self.format = matchFormat +// self.startDate = startDate +// self.groupStageLoserBracket = groupStageLoserBracket +// self.loserBracketMode = loserBracketMode + } + + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) } // MARK: - Computed dependencies @@ -542,7 +549,7 @@ defer { if let seedInterval = seedInterval(initialMode: initialMode) { return seedInterval.localizedLabel(displayStyle) } - print("Round pas trouvé", id, parent, index) +// print("Round pas trouvé", id, parent, index) return "Match de classement" } return RoundRule.roundName(fromRoundIndex: index, displayStyle: displayStyle) @@ -619,7 +626,7 @@ defer { let matches = (0.. String { "team-registrations" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return true } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var tournament: String - var groupStage: String? - var registrationDate: Date? - var callDate: Date? - var bracketPosition: Int? - var groupStagePosition: Int? - var comment: String? - var source: String? - var sourceValue: String? - var logo: String? - var name: String? - - var walkOut: Bool = false - var wildCardBracket: Bool = false - var wildCardGroupStage: Bool = false - var weight: Int = 0 - var lockedWeight: Int? - var confirmationDate: Date? - var qualified: Bool = false - var finalRanking: Int? - var pointsEarned: Int? - - var storeId: String? = nil +final class TeamRegistration: BaseTeamRegistration, SideStorable { + +// static func resourceName() -> String { "team-registrations" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return true } +// static var relationshipNames: [String] = [] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var tournament: String +// var groupStage: String? +// var registrationDate: Date? +// var callDate: Date? +// var bracketPosition: Int? +// var groupStagePosition: Int? +// var comment: String? +// var source: String? +// var sourceValue: String? +// var logo: String? +// var name: String? +// +// var walkOut: Bool = false +// var wildCardBracket: Bool = false +// var wildCardGroupStage: Bool = false +// var weight: Int = 0 +// var lockedWeight: Int? +// var confirmationDate: Date? +// var qualified: Bool = false +// var finalRanking: Int? +// var pointsEarned: Int? +// +// var storeId: String? = nil init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil, walkOut: Bool = false, wildCardBracket: Bool = false, wildCardGroupStage: Bool = false, weight: Int = 0, lockedWeight: Int? = nil, confirmationDate: Date? = nil, qualified: Bool = false) { - self.storeId = tournament - self.lastUpdate = Date() + super.init(storeId: tournament) + +// self.storeId = tournament self.tournament = tournament self.groupStage = groupStage self.registrationDate = registrationDate @@ -66,6 +68,10 @@ final class TeamRegistration: ModelObject, SyncedStorable, SideStorable { self.qualified = qualified } + required init(from decoder: any Decoder) throws { + try super.init(from: decoder) + } + var tournamentStore: TournamentStore { return TournamentStore.instance(tournamentId: self.tournament) } @@ -509,59 +515,59 @@ final class TeamRegistration: ModelObject, SyncedStorable, SideStorable { return nil } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _storeId = "storeId" - case _tournament = "tournament" - case _groupStage = "groupStage" - case _registrationDate = "registrationDate" - case _callDate = "callDate" - case _bracketPosition = "bracketPosition" - case _groupStagePosition = "groupStagePosition" - case _comment = "comment" - case _source = "source" - case _sourceValue = "sourceValue" - case _logo = "logo" - case _name = "name" - case _wildCardBracket = "wildCardBracket" - case _wildCardGroupStage = "wildCardGroupStage" - case _weight = "weight" - case _walkOut = "walkOut" - case _lockedWeight = "lockedWeight" - case _confirmationDate = "confirmationDate" - case _qualified = "qualified" - case _finalRanking = "finalRanking" - case _pointsEarned = "pointsEarned" - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(storeId, forKey: ._storeId) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(tournament, forKey: ._tournament) - try container.encode(groupStage, forKey: ._groupStage) - try container.encode(registrationDate, forKey: ._registrationDate) - try container.encode(callDate, forKey: ._callDate) - try container.encode(bracketPosition, forKey: ._bracketPosition) - try container.encode(groupStagePosition, forKey: ._groupStagePosition) - try container.encode(comment, forKey: ._comment) - try container.encode(source, forKey: ._source) - try container.encode(sourceValue, forKey: ._sourceValue) - try container.encode(logo, forKey: ._logo) - try container.encode(name, forKey: ._name) - try container.encode(walkOut, forKey: ._walkOut) - try container.encode(wildCardBracket, forKey: ._wildCardBracket) - try container.encode(wildCardGroupStage, forKey: ._wildCardGroupStage) - try container.encode(weight, forKey: ._weight) - try container.encode(lockedWeight, forKey: ._lockedWeight) - try container.encode(confirmationDate, forKey: ._confirmationDate) - try container.encode(qualified, forKey: ._qualified) - try container.encode(finalRanking, forKey: ._finalRanking) - try container.encode(pointsEarned, forKey: ._pointsEarned) - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _lastUpdate = "lastUpdate" +// case _storeId = "storeId" +// case _tournament = "tournament" +// case _groupStage = "groupStage" +// case _registrationDate = "registrationDate" +// case _callDate = "callDate" +// case _bracketPosition = "bracketPosition" +// case _groupStagePosition = "groupStagePosition" +// case _comment = "comment" +// case _source = "source" +// case _sourceValue = "sourceValue" +// case _logo = "logo" +// case _name = "name" +// case _wildCardBracket = "wildCardBracket" +// case _wildCardGroupStage = "wildCardGroupStage" +// case _weight = "weight" +// case _walkOut = "walkOut" +// case _lockedWeight = "lockedWeight" +// case _confirmationDate = "confirmationDate" +// case _qualified = "qualified" +// case _finalRanking = "finalRanking" +// case _pointsEarned = "pointsEarned" +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(storeId, forKey: ._storeId) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(tournament, forKey: ._tournament) +// try container.encode(groupStage, forKey: ._groupStage) +// try container.encode(registrationDate, forKey: ._registrationDate) +// try container.encode(callDate, forKey: ._callDate) +// try container.encode(bracketPosition, forKey: ._bracketPosition) +// try container.encode(groupStagePosition, forKey: ._groupStagePosition) +// try container.encode(comment, forKey: ._comment) +// try container.encode(source, forKey: ._source) +// try container.encode(sourceValue, forKey: ._sourceValue) +// try container.encode(logo, forKey: ._logo) +// try container.encode(name, forKey: ._name) +// try container.encode(walkOut, forKey: ._walkOut) +// try container.encode(wildCardBracket, forKey: ._wildCardBracket) +// try container.encode(wildCardGroupStage, forKey: ._wildCardGroupStage) +// try container.encode(weight, forKey: ._weight) +// try container.encode(lockedWeight, forKey: ._lockedWeight) +// try container.encode(confirmationDate, forKey: ._confirmationDate) +// try container.encode(qualified, forKey: ._qualified) +// try container.encode(finalRanking, forKey: ._finalRanking) +// try container.encode(pointsEarned, forKey: ._pointsEarned) +// } func insertOnServer() { self.tournamentStore.teamRegistrations.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClub/Data/TeamScore.swift b/PadelClub/Data/TeamScore.swift index b996fca..945191f 100644 --- a/PadelClub/Data/TeamScore.swift +++ b/PadelClub/Data/TeamScore.swift @@ -9,44 +9,45 @@ import Foundation import LeStorage @Observable -final class TeamScore: ModelObject, SyncedStorable, SideStorable { +final class TeamScore: BaseTeamScore, SideStorable { + - static func resourceName() -> String { "team-scores" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return true } - static var relationshipNames: [String] = ["match"] - - var id: String = Store.randomId() - var lastUpdate: Date - var match: String - var teamRegistration: String? - //var playerRegistrations: [String] = [] - var score: String? - var walkOut: Int? - var luckyLoser: Int? - - var storeId: String? = nil +// static func resourceName() -> String { "team-scores" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return true } +// static var relationshipNames: [String] = ["match"] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var match: String +// var teamRegistration: String? +// //var playerRegistrations: [String] = [] +// var score: String? +// var walkOut: Int? +// var luckyLoser: Int? +// +// var storeId: String? = nil init(match: String, teamRegistration: String? = nil, score: String? = nil, walkOut: Int? = nil, luckyLoser: Int? = nil) { - self.lastUpdate = Date() - self.match = match - self.teamRegistration = teamRegistration -// self.playerRegistrations = playerRegistrations - self.score = score - self.walkOut = walkOut - self.luckyLoser = luckyLoser + super.init(match: match, teamRegistration: teamRegistration, score: score, walkOut: walkOut, luckyLoser: luckyLoser) + +// self.match = match +// self.teamRegistration = teamRegistration +//// self.playerRegistrations = playerRegistrations +// self.score = score +// self.walkOut = walkOut +// self.luckyLoser = luckyLoser } init(match: String, team: TeamRegistration?) { - self.lastUpdate = Date() - self.match = match + super.init(match: match) if let team { self.teamRegistration = team.id - //self.playerRegistrations = team.players().map { $0.id } } - self.score = nil - self.walkOut = nil - self.luckyLoser = nil + } + + required init(from decoder: Decoder) throws { + try super.init(from: decoder) } var tournamentStore: TournamentStore { @@ -75,30 +76,30 @@ final class TeamScore: ModelObject, SyncedStorable, SideStorable { return walkOut != nil } - enum CodingKeys: String, CodingKey { - case _id = "id" - case _storeId = "storeId" - case _lastUpdate = "lastUpdate" - case _match = "match" - case _teamRegistration = "teamRegistration" - //case _playerRegistrations = "playerRegistrations" - case _score = "score" - case _walkOut = "walkOut" - case _luckyLoser = "luckyLoser" - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(storeId, forKey: ._storeId) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(match, forKey: ._match) - try container.encode(teamRegistration, forKey: ._teamRegistration) - try container.encode(score, forKey: ._score) - try container.encode(walkOut, forKey: ._walkOut) - try container.encode(luckyLoser, forKey: ._luckyLoser) - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _storeId = "storeId" +// case _lastUpdate = "lastUpdate" +// case _match = "match" +// case _teamRegistration = "teamRegistration" +// //case _playerRegistrations = "playerRegistrations" +// case _score = "score" +// case _walkOut = "walkOut" +// case _luckyLoser = "luckyLoser" +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(storeId, forKey: ._storeId) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(match, forKey: ._match) +// try container.encode(teamRegistration, forKey: ._teamRegistration) +// try container.encode(score, forKey: ._score) +// try container.encode(walkOut, forKey: ._walkOut) +// try container.encode(luckyLoser, forKey: ._luckyLoser) +// } func insertOnServer() { self.tournamentStore.teamScores.writeChangeAndInsertOnServer(instance: self) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index bc5f7e0..f9d60eb 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -10,112 +10,113 @@ import LeStorage import SwiftUI @Observable -final class Tournament: ModelObject, SyncedStorable { - - static func resourceName() -> String { "tournaments" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - var id: String = Store.randomId() - var lastUpdate: Date - var event: String? - var name: String? - var startDate: Date - var endDate: Date? - private(set) var creationDate: Date - var isPrivate: Bool - private(set) var groupStageFormat: MatchFormat? - private(set) var roundFormat: MatchFormat? - private(set) var loserRoundFormat: MatchFormat? - var groupStageSortMode: GroupStageOrderingMode - var groupStageCount: Int - var rankSourceDate: Date? - var dayDuration: Int - var teamCount: Int - var teamSorting: TeamSortingType - var federalCategory: TournamentCategory - var federalLevelCategory: TournamentLevel - var federalAgeCategory: FederalTournamentAge - var closedRegistrationDate: Date? - var groupStageAdditionalQualified: Int - var courtCount: Int = 2 - var prioritizeClubMembers: Bool - var qualifiedPerGroupStage: Int - var teamsPerGroupStage: Int - var entryFee: Double? - var payment: TournamentPayment? = nil - var additionalEstimationDuration: Int = 0 - var isDeleted: Bool = false - var isCanceled: Bool = false - var publishTeams: Bool = false - //var publishWaitingList: Bool = false - var publishSummons: Bool = false - var publishGroupStages: Bool = false - var publishBrackets: Bool = false - var shouldVerifyGroupStage: Bool = false - var shouldVerifyBracket: Bool = false - var hideTeamsWeight: Bool = false - var publishTournament: Bool = false - var hidePointsEarned: Bool = false - var publishRankings: Bool = false - var loserBracketMode: LoserBracketMode = .automatic +final class Tournament: BaseTournament { + +// static func resourceName() -> String { "tournaments" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return false } +// static var relationshipNames: [String] = [] +// +// var id: String = Store.randomId() +// var lastUpdate: Date +// var event: String? +// var name: String? +// var startDate: Date +// var endDate: Date? +// private(set) var creationDate: Date +// var isPrivate: Bool +// private(set) var groupStageFormat: MatchFormat? +// private(set) var roundFormat: MatchFormat? +// private(set) var loserRoundFormat: MatchFormat? +// var groupStageSortMode: GroupStageOrderingMode +// var groupStageCount: Int +// var rankSourceDate: Date? +// var dayDuration: Int +// var teamCount: Int +// var teamSorting: TeamSortingType +// var federalCategory: TournamentCategory +// var federalLevelCategory: TournamentLevel +// var federalAgeCategory: FederalTournamentAge +// var closedRegistrationDate: Date? +// var groupStageAdditionalQualified: Int +// var courtCount: Int = 2 +// var prioritizeClubMembers: Bool +// var qualifiedPerGroupStage: Int +// var teamsPerGroupStage: Int +// var entryFee: Double? +// var payment: TournamentPayment? = nil +// var additionalEstimationDuration: Int = 0 +// var isDeleted: Bool = false +// var isCanceled: Bool = false +// var publishTeams: Bool = false +// //var publishWaitingList: Bool = false +// var publishSummons: Bool = false +// var publishGroupStages: Bool = false +// var publishBrackets: Bool = false +// var shouldVerifyGroupStage: Bool = false +// var shouldVerifyBracket: Bool = false +// var hideTeamsWeight: Bool = false +// var publishTournament: Bool = false +// var hidePointsEarned: Bool = false +// var publishRankings: Bool = false +// var loserBracketMode: LoserBracketMode = .automatic var storeId: String? { return nil } @ObservationIgnored var navigationPath: [Screen] = [] - enum CodingKeys: String, CodingKey { - case _id = "id" - case _lastUpdate = "lastUpdate" - case _event = "event" - case _creator = "creator" - case _name = "name" - case _startDate = "startDate" - case _endDate = "endDate" - case _creationDate = "creationDate" - case _isPrivate = "isPrivate" - case _groupStageFormat = "groupStageFormat" - case _roundFormat = "roundFormat" - case _loserRoundFormat = "loserRoundFormat" - case _groupStageSortMode = "groupStageSortMode" - case _groupStageCount = "groupStageCount" - case _rankSourceDate = "rankSourceDate" - case _dayDuration = "dayDuration" - case _teamCount = "teamCount" - case _teamSorting = "teamSorting" - case _federalCategory = "federalCategory" - case _federalLevelCategory = "federalLevelCategory" - case _federalAgeCategory = "federalAgeCategory" - case _seedCount = "seedCount" - case _closedRegistrationDate = "closedRegistrationDate" - case _groupStageAdditionalQualified = "groupStageAdditionalQualified" - case _courtCount = "courtCount" - case _prioritizeClubMembers = "prioritizeClubMembers" - case _qualifiedPerGroupStage = "qualifiedPerGroupStage" - case _teamsPerGroupStage = "teamsPerGroupStage" - case _entryFee = "entryFee" - case _additionalEstimationDuration = "additionalEstimationDuration" - case _isDeleted = "isDeleted" - case _isCanceled = "localId" - case _payment = "globalId" - case _publishTeams = "publishTeams" - //case _publishWaitingList = "publishWaitingList" - case _publishSummons = "publishSummons" - case _publishGroupStages = "publishGroupStages" - case _publishBrackets = "publishBrackets" - case _shouldVerifyGroupStage = "shouldVerifyGroupStage" - case _shouldVerifyBracket = "shouldVerifyBracket" - case _hideTeamsWeight = "hideTeamsWeight" - case _publishTournament = "publishTournament" - case _hidePointsEarned = "hidePointsEarned" - case _publishRankings = "publishRankings" - case _loserBracketMode = "loserBracketMode" - } +// enum CodingKeys: String, CodingKey { +// case _id = "id" +// case _lastUpdate = "lastUpdate" +// case _event = "event" +// case _creator = "creator" +// case _name = "name" +// case _startDate = "startDate" +// case _endDate = "endDate" +// case _creationDate = "creationDate" +// case _isPrivate = "isPrivate" +// case _groupStageFormat = "groupStageFormat" +// case _roundFormat = "roundFormat" +// case _loserRoundFormat = "loserRoundFormat" +// case _groupStageSortMode = "groupStageSortMode" +// case _groupStageCount = "groupStageCount" +// case _rankSourceDate = "rankSourceDate" +// case _dayDuration = "dayDuration" +// case _teamCount = "teamCount" +// case _teamSorting = "teamSorting" +// case _federalCategory = "federalCategory" +// case _federalLevelCategory = "federalLevelCategory" +// case _federalAgeCategory = "federalAgeCategory" +// case _seedCount = "seedCount" +// case _closedRegistrationDate = "closedRegistrationDate" +// case _groupStageAdditionalQualified = "groupStageAdditionalQualified" +// case _courtCount = "courtCount" +// case _prioritizeClubMembers = "prioritizeClubMembers" +// case _qualifiedPerGroupStage = "qualifiedPerGroupStage" +// case _teamsPerGroupStage = "teamsPerGroupStage" +// case _entryFee = "entryFee" +// case _additionalEstimationDuration = "additionalEstimationDuration" +// case _isDeleted = "isDeleted" +// case _isCanceled = "localId" +// case _payment = "globalId" +// case _publishTeams = "publishTeams" +// //case _publishWaitingList = "publishWaitingList" +// case _publishSummons = "publishSummons" +// case _publishGroupStages = "publishGroupStages" +// case _publishBrackets = "publishBrackets" +// case _shouldVerifyGroupStage = "shouldVerifyGroupStage" +// case _shouldVerifyBracket = "shouldVerifyBracket" +// case _hideTeamsWeight = "hideTeamsWeight" +// case _publishTournament = "publishTournament" +// case _hidePointsEarned = "hidePointsEarned" +// case _publishRankings = "publishRankings" +// case _loserBracketMode = "loserBracketMode" +// } internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = false, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil, additionalEstimationDuration: Int = 0, isDeleted: Bool = false, publishTeams: Bool = false, publishSummons: Bool = false, publishGroupStages: Bool = false, publishBrackets: Bool = false, shouldVerifyBracket: Bool = false, shouldVerifyGroupStage: Bool = false, hideTeamsWeight: Bool = false, publishTournament: Bool = false, hidePointsEarned: Bool = false, publishRankings: Bool = false, loserBracketMode: LoserBracketMode = .automatic) { - self.lastUpdate = Date() + super.init() + self.event = event self.name = name self.startDate = startDate @@ -157,173 +158,177 @@ final class Tournament: ModelObject, SyncedStorable { } required init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - id = try container.decode(String.self, forKey: ._id) - lastUpdate = try container.decode(Date.self, forKey: ._lastUpdate) - event = try container.decodeIfPresent(String.self, forKey: ._event) - name = try container.decodeIfPresent(String.self, forKey: ._name) - startDate = try container.decode(Date.self, forKey: ._startDate) - endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) - creationDate = try container.decode(Date.self, forKey: ._creationDate) - isPrivate = try container.decode(Bool.self, forKey: ._isPrivate) - groupStageFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._groupStageFormat) - roundFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._roundFormat) - loserRoundFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserRoundFormat) - groupStageSortMode = try container.decode(GroupStageOrderingMode.self, forKey: ._groupStageSortMode) - groupStageCount = try container.decode(Int.self, forKey: ._groupStageCount) - rankSourceDate = try container.decodeIfPresent(Date.self, forKey: ._rankSourceDate) - dayDuration = try container.decode(Int.self, forKey: ._dayDuration) - teamCount = try container.decode(Int.self, forKey: ._teamCount) - teamSorting = try container.decode(TeamSortingType.self, forKey: ._teamSorting) - federalCategory = try container.decode(TournamentCategory.self, forKey: ._federalCategory) - federalLevelCategory = try container.decode(TournamentLevel.self, forKey: ._federalLevelCategory) - federalAgeCategory = try container.decode(FederalTournamentAge.self, forKey: ._federalAgeCategory) - closedRegistrationDate = try container.decodeIfPresent(Date.self, forKey: ._closedRegistrationDate) - groupStageAdditionalQualified = try container.decode(Int.self, forKey: ._groupStageAdditionalQualified) - courtCount = try container.decode(Int.self, forKey: ._courtCount) - prioritizeClubMembers = try container.decode(Bool.self, forKey: ._prioritizeClubMembers) - qualifiedPerGroupStage = try container.decode(Int.self, forKey: ._qualifiedPerGroupStage) - teamsPerGroupStage = try container.decode(Int.self, forKey: ._teamsPerGroupStage) - entryFee = try container.decodeIfPresent(Double.self, forKey: ._entryFee) - payment = try Tournament._decodePayment(container: container) - additionalEstimationDuration = try container.decode(Int.self, forKey: ._additionalEstimationDuration) - isDeleted = try container.decode(Bool.self, forKey: ._isDeleted) - isCanceled = try Tournament._decodeCanceled(container: container) - publishTeams = try container.decodeIfPresent(Bool.self, forKey: ._publishTeams) ?? false - publishSummons = try container.decodeIfPresent(Bool.self, forKey: ._publishSummons) ?? false - publishGroupStages = try container.decodeIfPresent(Bool.self, forKey: ._publishGroupStages) ?? false - publishBrackets = try container.decodeIfPresent(Bool.self, forKey: ._publishBrackets) ?? false - shouldVerifyBracket = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyBracket) ?? false - shouldVerifyGroupStage = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyGroupStage) ?? false - hideTeamsWeight = try container.decodeIfPresent(Bool.self, forKey: ._hideTeamsWeight) ?? false - publishTournament = try container.decodeIfPresent(Bool.self, forKey: ._publishTournament) ?? false - hidePointsEarned = try container.decodeIfPresent(Bool.self, forKey: ._hidePointsEarned) ?? false - publishRankings = try container.decodeIfPresent(Bool.self, forKey: ._publishRankings) ?? false - loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic - } - - fileprivate static let _numberFormatter: NumberFormatter = NumberFormatter() - - fileprivate static func _decodePayment(container: KeyedDecodingContainer) throws -> TournamentPayment? { - let data = try container.decodeIfPresent(Data.self, forKey: ._payment) - - if let data { - do { - let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue) - let sequence = decoded.compactMap { _numberFormatter.number(from: String($0))?.intValue } - return TournamentPayment(rawValue: sequence[18]) - } catch { - Logger.error(error) - } - } - return nil - } - - fileprivate static func _decodeCanceled(container: KeyedDecodingContainer) throws -> Bool { - let data = try container.decodeIfPresent(Data.self, forKey: ._isCanceled) - if let data { - do { - let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue) - let sequence = decoded.compactMap { _numberFormatter.number(from: String($0))?.intValue } - return Bool.decodeInt(sequence[18]) - } catch { - Logger.error(error) - } - } - return false - } - - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(id, forKey: ._id) - try container.encode(lastUpdate, forKey: ._lastUpdate) - try container.encode(event, forKey: ._event) - try container.encode(name, forKey: ._name) - - try container.encode(startDate, forKey: ._startDate) - try container.encode(endDate, forKey: ._endDate) - - try container.encode(creationDate, forKey: ._creationDate) - try container.encode(isPrivate, forKey: ._isPrivate) - - try container.encode(groupStageFormat, forKey: ._groupStageFormat) - try container.encode(roundFormat, forKey: ._roundFormat) - try container.encode(loserRoundFormat, forKey: ._loserRoundFormat) - - try container.encode(groupStageSortMode, forKey: ._groupStageSortMode) - try container.encode(groupStageCount, forKey: ._groupStageCount) - - try container.encode(rankSourceDate, forKey: ._rankSourceDate) - - try container.encode(dayDuration, forKey: ._dayDuration) - try container.encode(teamCount, forKey: ._teamCount) - try container.encode(teamSorting, forKey: ._teamSorting) - try container.encode(federalCategory, forKey: ._federalCategory) - try container.encode(federalLevelCategory, forKey: ._federalLevelCategory) - try container.encode(federalAgeCategory, forKey: ._federalAgeCategory) - - try container.encode(closedRegistrationDate, forKey: ._closedRegistrationDate) - - try container.encode(groupStageAdditionalQualified, forKey: ._groupStageAdditionalQualified) - try container.encode(courtCount, forKey: ._courtCount) - try container.encode(prioritizeClubMembers, forKey: ._prioritizeClubMembers) - try container.encode(qualifiedPerGroupStage, forKey: ._qualifiedPerGroupStage) - try container.encode(teamsPerGroupStage, forKey: ._teamsPerGroupStage) - try container.encode(entryFee, forKey: ._entryFee) - - try self._encodePayment(container: &container) - try container.encode(additionalEstimationDuration, forKey: ._additionalEstimationDuration) - try container.encode(isDeleted, forKey: ._isDeleted) - try self._encodeIsCanceled(container: &container) - try container.encode(publishTeams, forKey: ._publishTeams) - try container.encode(publishSummons, forKey: ._publishSummons) - try container.encode(publishBrackets, forKey: ._publishBrackets) - try container.encode(publishGroupStages, forKey: ._publishGroupStages) - try container.encode(shouldVerifyBracket, forKey: ._shouldVerifyBracket) - try container.encode(shouldVerifyGroupStage, forKey: ._shouldVerifyGroupStage) - try container.encode(hideTeamsWeight, forKey: ._hideTeamsWeight) - try container.encode(publishTournament, forKey: ._publishTournament) - try container.encode(hidePointsEarned, forKey: ._hidePointsEarned) - try container.encode(publishRankings, forKey: ._publishRankings) - try container.encode(loserBracketMode, forKey: ._loserBracketMode) - } - - fileprivate func _encodePayment(container: inout KeyedEncodingContainer) throws { - - guard let payment else { - try container.encodeNil(forKey: ._payment) - return - } - - let max: Int = TournamentPayment.allCases.count - var sequence = (1...18).map { _ in Int.random(in: (0..) throws { - - let max: Int = 9 - var sequence = (1...18).map { _ in Int.random(in: (0...max)) } - sequence.append(self.isCanceled.encodedValue) - sequence.append(contentsOf: (1...13).map { _ in Int.random(in: (0...max ))} ) - - let stringCombo: [String] = sequence.map { $0.formatted() } - let joined: String = stringCombo.joined(separator: "") - if let data = joined.data(using: .utf8) { - let encryped: Data = try data.encrypt(pass: CryptoKey.pass.rawValue) - try container.encode(encryped, forKey: ._isCanceled) - } - } + try super.init(from: decoder) + } + +// required init(from decoder: Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// id = try container.decode(String.self, forKey: ._id) +// lastUpdate = try container.decode(Date.self, forKey: ._lastUpdate) +// event = try container.decodeIfPresent(String.self, forKey: ._event) +// name = try container.decodeIfPresent(String.self, forKey: ._name) +// startDate = try container.decode(Date.self, forKey: ._startDate) +// endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) +// creationDate = try container.decode(Date.self, forKey: ._creationDate) +// isPrivate = try container.decode(Bool.self, forKey: ._isPrivate) +// groupStageFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._groupStageFormat) +// roundFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._roundFormat) +// loserRoundFormat = try container.decodeIfPresent(MatchFormat.self, forKey: ._loserRoundFormat) +// groupStageSortMode = try container.decode(GroupStageOrderingMode.self, forKey: ._groupStageSortMode) +// groupStageCount = try container.decode(Int.self, forKey: ._groupStageCount) +// rankSourceDate = try container.decodeIfPresent(Date.self, forKey: ._rankSourceDate) +// dayDuration = try container.decode(Int.self, forKey: ._dayDuration) +// teamCount = try container.decode(Int.self, forKey: ._teamCount) +// teamSorting = try container.decode(TeamSortingType.self, forKey: ._teamSorting) +// federalCategory = try container.decode(TournamentCategory.self, forKey: ._federalCategory) +// federalLevelCategory = try container.decode(TournamentLevel.self, forKey: ._federalLevelCategory) +// federalAgeCategory = try container.decode(FederalTournamentAge.self, forKey: ._federalAgeCategory) +// closedRegistrationDate = try container.decodeIfPresent(Date.self, forKey: ._closedRegistrationDate) +// groupStageAdditionalQualified = try container.decode(Int.self, forKey: ._groupStageAdditionalQualified) +// courtCount = try container.decode(Int.self, forKey: ._courtCount) +// prioritizeClubMembers = try container.decode(Bool.self, forKey: ._prioritizeClubMembers) +// qualifiedPerGroupStage = try container.decode(Int.self, forKey: ._qualifiedPerGroupStage) +// teamsPerGroupStage = try container.decode(Int.self, forKey: ._teamsPerGroupStage) +// entryFee = try container.decodeIfPresent(Double.self, forKey: ._entryFee) +// payment = try Tournament._decodePayment(container: container) +// additionalEstimationDuration = try container.decode(Int.self, forKey: ._additionalEstimationDuration) +// isDeleted = try container.decode(Bool.self, forKey: ._isDeleted) +// isCanceled = try Tournament._decodeCanceled(container: container) +// publishTeams = try container.decodeIfPresent(Bool.self, forKey: ._publishTeams) ?? false +// publishSummons = try container.decodeIfPresent(Bool.self, forKey: ._publishSummons) ?? false +// publishGroupStages = try container.decodeIfPresent(Bool.self, forKey: ._publishGroupStages) ?? false +// publishBrackets = try container.decodeIfPresent(Bool.self, forKey: ._publishBrackets) ?? false +// shouldVerifyBracket = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyBracket) ?? false +// shouldVerifyGroupStage = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyGroupStage) ?? false +// hideTeamsWeight = try container.decodeIfPresent(Bool.self, forKey: ._hideTeamsWeight) ?? false +// publishTournament = try container.decodeIfPresent(Bool.self, forKey: ._publishTournament) ?? false +// hidePointsEarned = try container.decodeIfPresent(Bool.self, forKey: ._hidePointsEarned) ?? false +// publishRankings = try container.decodeIfPresent(Bool.self, forKey: ._publishRankings) ?? false +// loserBracketMode = try container.decodeIfPresent(LoserBracketMode.self, forKey: ._loserBracketMode) ?? .automatic +// } +// +// fileprivate static let _numberFormatter: NumberFormatter = NumberFormatter() +// +// fileprivate static func _decodePayment(container: KeyedDecodingContainer) throws -> TournamentPayment? { +// let data = try container.decodeIfPresent(Data.self, forKey: ._payment) +// +// if let data { +// do { +// let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue) +// let sequence = decoded.compactMap { _numberFormatter.number(from: String($0))?.intValue } +// return TournamentPayment(rawValue: sequence[18]) +// } catch { +// Logger.error(error) +// } +// } +// return nil +// } +// +// fileprivate static func _decodeCanceled(container: KeyedDecodingContainer) throws -> Bool { +// let data = try container.decodeIfPresent(Data.self, forKey: ._isCanceled) +// if let data { +// do { +// let decoded: String = try data.decryptData(pass: CryptoKey.pass.rawValue) +// let sequence = decoded.compactMap { _numberFormatter.number(from: String($0))?.intValue } +// return Bool.decodeInt(sequence[18]) +// } catch { +// Logger.error(error) +// } +// } +// return false +// } +// +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(id, forKey: ._id) +// try container.encode(lastUpdate, forKey: ._lastUpdate) +// try container.encode(event, forKey: ._event) +// try container.encode(name, forKey: ._name) +// +// try container.encode(startDate, forKey: ._startDate) +// try container.encode(endDate, forKey: ._endDate) +// +// try container.encode(creationDate, forKey: ._creationDate) +// try container.encode(isPrivate, forKey: ._isPrivate) +// +// try container.encode(groupStageFormat, forKey: ._groupStageFormat) +// try container.encode(roundFormat, forKey: ._roundFormat) +// try container.encode(loserRoundFormat, forKey: ._loserRoundFormat) +// +// try container.encode(groupStageSortMode, forKey: ._groupStageSortMode) +// try container.encode(groupStageCount, forKey: ._groupStageCount) +// +// try container.encode(rankSourceDate, forKey: ._rankSourceDate) +// +// try container.encode(dayDuration, forKey: ._dayDuration) +// try container.encode(teamCount, forKey: ._teamCount) +// try container.encode(teamSorting, forKey: ._teamSorting) +// try container.encode(federalCategory, forKey: ._federalCategory) +// try container.encode(federalLevelCategory, forKey: ._federalLevelCategory) +// try container.encode(federalAgeCategory, forKey: ._federalAgeCategory) +// +// try container.encode(closedRegistrationDate, forKey: ._closedRegistrationDate) +// +// try container.encode(groupStageAdditionalQualified, forKey: ._groupStageAdditionalQualified) +// try container.encode(courtCount, forKey: ._courtCount) +// try container.encode(prioritizeClubMembers, forKey: ._prioritizeClubMembers) +// try container.encode(qualifiedPerGroupStage, forKey: ._qualifiedPerGroupStage) +// try container.encode(teamsPerGroupStage, forKey: ._teamsPerGroupStage) +// try container.encode(entryFee, forKey: ._entryFee) +// +// try self._encodePayment(container: &container) +// try container.encode(additionalEstimationDuration, forKey: ._additionalEstimationDuration) +// try container.encode(isDeleted, forKey: ._isDeleted) +// try self._encodeIsCanceled(container: &container) +// try container.encode(publishTeams, forKey: ._publishTeams) +// try container.encode(publishSummons, forKey: ._publishSummons) +// try container.encode(publishBrackets, forKey: ._publishBrackets) +// try container.encode(publishGroupStages, forKey: ._publishGroupStages) +// try container.encode(shouldVerifyBracket, forKey: ._shouldVerifyBracket) +// try container.encode(shouldVerifyGroupStage, forKey: ._shouldVerifyGroupStage) +// try container.encode(hideTeamsWeight, forKey: ._hideTeamsWeight) +// try container.encode(publishTournament, forKey: ._publishTournament) +// try container.encode(hidePointsEarned, forKey: ._hidePointsEarned) +// try container.encode(publishRankings, forKey: ._publishRankings) +// try container.encode(loserBracketMode, forKey: ._loserBracketMode) +// } +// +// fileprivate func _encodePayment(container: inout KeyedEncodingContainer) throws { +// +// guard let payment else { +// try container.encodeNil(forKey: ._payment) +// return +// } +// +// let max: Int = TournamentPayment.allCases.count +// var sequence = (1...18).map { _ in Int.random(in: (0..) throws { +// +// let max: Int = 9 +// var sequence = (1...18).map { _ in Int.random(in: (0...max)) } +// sequence.append(self.isCanceled.encodedValue) +// sequence.append(contentsOf: (1...13).map { _ in Int.random(in: (0...max ))} ) +// +// let stringCombo: [String] = sequence.map { $0.formatted() } +// let joined: String = stringCombo.joined(separator: "") +// if let data = joined.data(using: .utf8) { +// let encryped: Data = try data.encrypt(pass: CryptoKey.pass.rawValue) +// try container.encode(encryped, forKey: ._isCanceled) +// } +// } var tournamentStore: TournamentStore { return TournamentStore.instance(tournamentId: self.id) @@ -373,21 +378,6 @@ final class Tournament: ModelObject, SyncedStorable { // MARK: - - /// Warning: if the enum has more than 10 cases, the payment algo is broken - enum TournamentPayment: Int, CaseIterable { - case free, unit, subscriptionUnit, unlimited - - var isSubscription: Bool { - switch self { - case .subscriptionUnit, .unlimited: - return true - default: - return false - } - } - - } - enum State { case initial case build @@ -479,8 +469,8 @@ final class Tournament: ModelObject, SyncedStorable { func shareURL(_ pageLink: PageLink = .matches) -> URL? { if pageLink == .clubBroadcast { let club = club() - print("club", club) - print("club broadcast code", club?.broadcastCode) +// print("club", club) +// print("club broadcast code", club?.broadcastCode) if let club, let broadcastCode = club.broadcastCode { return URLs.main.url.appending(path: "c/\(broadcastCode)") } else { @@ -947,7 +937,7 @@ defer { return self.selectedSortedTeams().flatMap { $0.unsortedPlayers() }.sorted(by: \.computedRank) } - func paidSelectedPlayers(type: PlayerRegistration.PlayerPaymentType) -> Double? { + func paidSelectedPlayers(type: PlayerPaymentType) -> Double? { if let entryFee { return Double(self.selectedSortedTeams().flatMap { $0.unsortedPlayers() }.filter { $0.paymentType == type }.count) * entryFee } else { @@ -1681,7 +1671,7 @@ defer { let matches = (0.. some View { DisclosureGroup { - ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in + ForEach(PlayerPaymentType.allCases) { type in PaymentTypeCashierRowView(tournaments: tournaments, type: type) } } label: { @@ -137,7 +137,7 @@ struct CashierDetailView: View { struct PaymentTypeCashierRowView: View { let tournaments: [Tournament] - let type: PlayerRegistration.PlayerPaymentType + let type: PlayerPaymentType @State private var value: Double? @@ -167,7 +167,7 @@ struct CashierDetailView: View { var body: some View { DisclosureGroup { let selectedPlayers = tournament.selectedPlayers() - ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in + ForEach(PlayerPaymentType.allCases) { type in let count = selectedPlayers.filter({ $0.paymentType == type }).count if count > 0 { LabeledContent { diff --git a/PadelClub/Views/Cashier/CashierSettingsView.swift b/PadelClub/Views/Cashier/CashierSettingsView.swift index fd51e73..d236a90 100644 --- a/PadelClub/Views/Cashier/CashierSettingsView.swift +++ b/PadelClub/Views/Cashier/CashierSettingsView.swift @@ -43,11 +43,7 @@ struct CashierSettingsView: View { players.forEach { player in player.hasArrived = true } - do { - try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) - } catch { - Logger.error(error) - } + tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) } } footer: { Text("Indique tous les joueurs sont là") @@ -59,11 +55,7 @@ struct CashierSettingsView: View { players.forEach { player in player.hasArrived = false } - do { - try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) - } catch { - Logger.error(error) - } + tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) } } footer: { Text("Indique qu'aucun joueur n'est arrivé") @@ -77,11 +69,7 @@ struct CashierSettingsView: View { player.paymentType = .gift } } - do { - try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) - } catch { - Logger.error(error) - } + tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) } } footer: { Text("Passe tous les joueurs qui n'ont pas réglé en offert") @@ -95,11 +83,7 @@ struct CashierSettingsView: View { players.forEach { player in player.paymentType = nil } - do { - try store.playerRegistrations.addOrUpdate(contentOfs: players) - } catch { - Logger.error(error) - } + store.playerRegistrations.addOrUpdate(contentOfs: players) } } footer: { Text("Remet à zéro le type d'encaissement de tous les joueurs") @@ -151,11 +135,7 @@ struct CashierSettingsView: View { } private func _save() { - do { - try dataStore.tournaments.addOrUpdate(instance: tournament) - } catch { - Logger.error(error) - } + dataStore.tournaments.addOrUpdate(instance: tournament) } } diff --git a/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift b/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift index adf8694..469971e 100644 --- a/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift +++ b/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift @@ -106,7 +106,7 @@ struct LoserBracketFromGroupStageView: View { private func _addNewMatch() { let currentGroupStageLoserBracketsInitialPlace = tournament.groupStageLoserBracketsInitialPlace() let placeCount = displayableMatches.isEmpty ? currentGroupStageLoserBracketsInitialPlace : max(currentGroupStageLoserBracketsInitialPlace, displayableMatches.map({ $0.index }).max()! + 2) - let match = Match(round: loserBracket.id, index: placeCount, matchFormat: loserBracket.matchFormat) + let match = Match(round: loserBracket.id, index: placeCount, format: loserBracket.matchFormat) match.name = "\(placeCount)\(placeCount.ordinalFormattedSuffix()) place" tournamentStore.matches.addOrUpdate(instance: match) } diff --git a/PadelClub/Views/Navigation/MainView.swift b/PadelClub/Views/Navigation/MainView.swift index 6fc905d..bf098ab 100644 --- a/PadelClub/Views/Navigation/MainView.swift +++ b/PadelClub/Views/Navigation/MainView.swift @@ -95,8 +95,8 @@ struct MainView: View { } .id(mainViewId) .onChange(of: dataStore.user.id) { - print("dataStore.user.id", dataStore.user.id) - print("StoreCenter.main.userId", StoreCenter.main.userId) + print("dataStore.user.id = ", dataStore.user.id) + print("StoreCenter.main.userId = ", StoreCenter.main.userId ?? "") if StoreCenter.main.userId == nil { // user disconnected navigation.path.removeLast(navigation.path.count) mainViewId = UUID() diff --git a/PadelClub/Views/Player/Components/PlayerPayView.swift b/PadelClub/Views/Player/Components/PlayerPayView.swift index 4382f14..e4e8b85 100644 --- a/PadelClub/Views/Player/Components/PlayerPayView.swift +++ b/PadelClub/Views/Player/Components/PlayerPayView.swift @@ -15,9 +15,9 @@ struct PlayerPayView: View { var body: some View { Picker(selection: $player.paymentType) { - Text("Non réglé").tag(nil as PlayerRegistration.PlayerPaymentType?) - ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in - Text(type.localizedLabel()).tag(type as PlayerRegistration.PlayerPaymentType?) + Text("Non réglé").tag(nil as PlayerPaymentType?) + ForEach(PlayerPaymentType.allCases) { type in + Text(type.localizedLabel()).tag(type as PlayerPaymentType?) } } label: { } @@ -29,10 +29,6 @@ struct PlayerPayView: View { } private func _save() { - do { - try tournamentStore.playerRegistrations.addOrUpdate(instance: player) - } catch { - Logger.error(error) - } + tournamentStore.playerRegistrations.addOrUpdate(instance: player) } } diff --git a/PadelClub/Views/Player/Components/PlayerPopoverView.swift b/PadelClub/Views/Player/Components/PlayerPopoverView.swift index 9bd893b..2a283a3 100644 --- a/PadelClub/Views/Player/Components/PlayerPopoverView.swift +++ b/PadelClub/Views/Player/Components/PlayerPopoverView.swift @@ -251,7 +251,7 @@ struct PlayerPopoverView: View { } func createManualPlayer() { - let playerRegistration = PlayerRegistration(firstName: firstName.trimmedMultiline, lastName: lastName.trimmedMultiline, licenceId: license.trimmedMultiline.isEmpty ? nil : license, rank: rank, sex: PlayerRegistration.PlayerSexType(rawValue: sex)) + let playerRegistration = PlayerRegistration(firstName: firstName.trimmedMultiline, lastName: lastName.trimmedMultiline, licenceId: license.trimmedMultiline.isEmpty ? nil : license, rank: rank, sex: PlayerSexType(rawValue: sex)) self.creationCompletionHandler(playerRegistration) } diff --git a/PadelClub/Views/Player/Components/PlayerSexPickerView.swift b/PadelClub/Views/Player/Components/PlayerSexPickerView.swift index 91e7527..f3cf674 100644 --- a/PadelClub/Views/Player/Components/PlayerSexPickerView.swift +++ b/PadelClub/Views/Player/Components/PlayerSexPickerView.swift @@ -23,8 +23,8 @@ struct PlayerSexPickerView: View { Text(player.playerLabel()) Spacer() Picker(selection: $player.sex) { - Text("Homme").tag(PlayerRegistration.PlayerSexType.male as PlayerRegistration.PlayerSexType?) - Text("Femme").tag(PlayerRegistration.PlayerSexType.female as PlayerRegistration.PlayerSexType?) + Text("Homme").tag(PlayerSexType.male as PlayerSexType?) + Text("Femme").tag(PlayerSexType.female as PlayerSexType?) } label: { } @@ -37,19 +37,11 @@ struct PlayerSexPickerView: View { } private func _save() { - do { - player.setComputedRank(in: tournament) - try tournamentStore.playerRegistrations.addOrUpdate(instance: player) - if let team = player.team() { - team.updateWeight(inTournamentCategory: tournament.tournamentCategory) - try tournamentStore.teamRegistrations.addOrUpdate(instance: team) - } - - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") + player.setComputedRank(in: tournament) + tournamentStore.playerRegistrations.addOrUpdate(instance: player) + if let team = player.team() { + team.updateWeight(inTournamentCategory: tournament.tournamentCategory) + tournamentStore.teamRegistrations.addOrUpdate(instance: team) } } diff --git a/PadelClub/Views/Round/RoundSettingsView.swift b/PadelClub/Views/Round/RoundSettingsView.swift index f095bc2..f0c23ab 100644 --- a/PadelClub/Views/Round/RoundSettingsView.swift +++ b/PadelClub/Views/Round/RoundSettingsView.swift @@ -92,7 +92,7 @@ struct RoundSettingsView: View { var currentIndex = 0 let matches = (0.. Tournament.TournamentPayment? { + func paymentForNewTournament() -> TournamentPayment? { switch self.currentPlan { case .monthlyUnlimited: - return Tournament.TournamentPayment.unlimited + return TournamentPayment.unlimited case .fivePerMonth: if let purchaseDate = self.currentBestPurchase?.purchaseDate { let tournaments = DataStore.shared.tournaments.filter { $0.creationDate > purchaseDate && $0.payment == .subscriptionUnit && $0.isCanceled == false } if tournaments.count < StoreItem.five { - return Tournament.TournamentPayment.subscriptionUnit + return TournamentPayment.subscriptionUnit } } return self._paymentWithoutSubscription() @@ -260,21 +260,21 @@ import LeStorage } - fileprivate func _paymentWithoutSubscription() -> Tournament.TournamentPayment? { + fileprivate func _paymentWithoutSubscription() -> TournamentPayment? { let freelyPayed: Int = DataStore.shared.tournaments.filter { $0.payment == .free && $0.isCanceled == false }.count if freelyPayed < 1 { - return Tournament.TournamentPayment.free + return TournamentPayment.free } let tournamentCreditCount: Int = self._purchasedTournamentCount() let unitlyPayed = DataStore.shared.tournaments.filter { $0.payment == .unit && $0.isCanceled == false }.count if tournamentCreditCount > unitlyPayed { - return Tournament.TournamentPayment.unit + return TournamentPayment.unit } return nil } var remainingTournaments: Int { - let unitlyPayed = DataStore.shared.tournaments.filter { $0.payment == Tournament.TournamentPayment.unit }.count + let unitlyPayed = DataStore.shared.tournaments.filter { $0.payment == TournamentPayment.unit }.count let tournamentCreditCount = self._purchasedTournamentCount() // let notDeletedTournamentCount = DataStore.shared.tournaments.filter { $0.isDeleted == false }.count diff --git a/PadelClub/Views/Tournament/Subscription/Purchase.swift b/PadelClub/Views/Tournament/Subscription/Purchase.swift index 06e1304..e7cfc24 100644 --- a/PadelClub/Views/Tournament/Subscription/Purchase.swift +++ b/PadelClub/Views/Tournament/Subscription/Purchase.swift @@ -8,45 +8,51 @@ import Foundation import LeStorage -class Purchase: ModelObject, SyncedStorable { +class Purchase: BasePurchase { - static func resourceName() -> String { return "purchases" } - static func tokenExemptedMethods() -> [HTTPMethod] { return [] } - static func filterByStoreIdentifier() -> Bool { return false } - static var relationshipNames: [String] = [] - - var id: UInt64 - var lastUpdate: Date - var user: String - var purchaseDate: Date - var productId: String - var quantity: Int? - var revocationDate: Date? = nil - var expirationDate: Date? = nil +// static func resourceName() -> String { return "purchases" } +// static func tokenExemptedMethods() -> [HTTPMethod] { return [] } +// static func filterByStoreIdentifier() -> Bool { return false } +// static var relationshipNames: [String] = [] +// +// var id: UInt64 +// var lastUpdate: Date +// var user: String +// var purchaseDate: Date +// var productId: String +// var quantity: Int? +// var revocationDate: Date? = nil +// var expirationDate: Date? = nil var storeId: String? { return nil } init(user: String, transactionId: UInt64, purchaseDate: Date, productId: String, quantity: Int? = nil, revocationDate: Date? = nil, expirationDate: Date? = nil) { - self.id = transactionId - self.lastUpdate = Date() - self.user = user - self.purchaseDate = purchaseDate - self.productId = productId - self.quantity = quantity - self.revocationDate = revocationDate - self.expirationDate = expirationDate + super.init(id: transactionId, user: user, purchaseDate: purchaseDate, productId: productId, quantity: quantity, revocationDate: revocationDate, expirationDate: expirationDate) + +// self.id = transactionId +// self.lastUpdate = Date() +// self.user = user +// self.purchaseDate = purchaseDate +// self.productId = productId +// self.quantity = quantity +// self.revocationDate = revocationDate +// self.expirationDate = expirationDate } - enum CodingKeys: String, CodingKey, CaseIterable { - case id - case lastUpdate - case user - case purchaseDate - case productId - case quantity - case revocationDate - case expirationDate + required init(from decoder: Decoder) throws { + try super.init(from: decoder) } + +// enum CodingKeys: String, CodingKey, CaseIterable { +// case id +// case lastUpdate +// case user +// case purchaseDate +// case productId +// case quantity +// case revocationDate +// case expirationDate +// } func isValid() -> Bool { guard self.revocationDate == nil else { @@ -58,30 +64,30 @@ class Purchase: ModelObject, SyncedStorable { return expiration > Date() } - func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(self.id, forKey: .id) - try container.encode(self.lastUpdate, forKey: .lastUpdate) - try container.encodeAndEncryptIfPresent(self.user.data(using: .utf8), forKey: .user) - try container.encode(self.purchaseDate, forKey: .purchaseDate) - try container.encode(self.productId, forKey: .productId) - try container.encode(self.quantity, forKey: .quantity) - try container.encode(self.revocationDate, forKey: .revocationDate) - try container.encode(self.expirationDate, forKey: .expirationDate) - } - - required init(from decoder: any Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - self.id = try container.decode(UInt64.self, forKey: .id) - self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: .lastUpdate) ?? Date() - self.user = try container.decodeEncrypted(key: .user) - self.purchaseDate = try container.decode(Date.self, forKey: .purchaseDate) - self.productId = try container.decode(String.self, forKey: .productId) - self.quantity = try container.decodeIfPresent(Int.self, forKey: .quantity) - self.revocationDate = try container.decodeIfPresent(Date.self, forKey: .revocationDate) - self.expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate) - } +// func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// +// try container.encode(self.id, forKey: .id) +// try container.encode(self.lastUpdate, forKey: .lastUpdate) +// try container.encodeAndEncryptIfPresent(self.user.data(using: .utf8), forKey: .user) +// try container.encode(self.purchaseDate, forKey: .purchaseDate) +// try container.encode(self.productId, forKey: .productId) +// try container.encode(self.quantity, forKey: .quantity) +// try container.encode(self.revocationDate, forKey: .revocationDate) +// try container.encode(self.expirationDate, forKey: .expirationDate) +// } +// +// required init(from decoder: any Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// +// self.id = try container.decode(UInt64.self, forKey: .id) +// self.lastUpdate = try container.decodeIfPresent(Date.self, forKey: .lastUpdate) ?? Date() +// self.user = try container.decodeEncrypted(key: .user) +// self.purchaseDate = try container.decode(Date.self, forKey: .purchaseDate) +// self.productId = try container.decode(String.self, forKey: .productId) +// self.quantity = try container.decodeIfPresent(Int.self, forKey: .quantity) +// self.revocationDate = try container.decodeIfPresent(Date.self, forKey: .revocationDate) +// self.expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate) +// } } diff --git a/PadelClub/Views/Tournament/Subscription/SubscriptionInfoView.swift b/PadelClub/Views/Tournament/Subscription/SubscriptionInfoView.swift index 4566f43..e3a21db 100644 --- a/PadelClub/Views/Tournament/Subscription/SubscriptionInfoView.swift +++ b/PadelClub/Views/Tournament/Subscription/SubscriptionInfoView.swift @@ -10,7 +10,7 @@ import TipKit struct SubscriptionInfoView: View { - @State var payment: Tournament.TournamentPayment? = .free + @State var payment: TournamentPayment? = .free var body: some View { diff --git a/PadelClub/Views/Tournament/TournamentView.swift b/PadelClub/Views/Tournament/TournamentView.swift index e12017a..c5645c6 100644 --- a/PadelClub/Views/Tournament/TournamentView.swift +++ b/PadelClub/Views/Tournament/TournamentView.swift @@ -210,16 +210,12 @@ struct TournamentView: View { } .onAppear { TournamentRunningTip.isRunning = tournament.state() == .running - Logger.log("Payment = \(String(describing: self.tournament.payment)), canceled = \(self.tournament.isCanceled)") + Logger.log("Tournament Id = \(self.tournament.id), Payment = \(String(describing: self.tournament.payment))") } } private func _save() { - do { - try dataStore.tournaments.addOrUpdate(instance: tournament) - } catch { - Logger.error(error) - } + dataStore.tournaments.addOrUpdate(instance: tournament) } }