diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 2e7d5bb..d4ade32 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -63,7 +63,6 @@ final class Tournament : ModelObject, Storable { var enableOnlineRegistration: Bool = false var registrationDateLimit: Date? = nil var openingRegistrationDate: Date? = nil - var targetTeamCount: Int? = nil var waitingListLimit: Int? = nil var accountIsRequired: Bool = true var licenseIsRequired: Bool = true @@ -124,7 +123,6 @@ final class Tournament : ModelObject, Storable { case _enableOnlineRegistration = "enableOnlineRegistration" case _registrationDateLimit = "registrationDateLimit" case _openingRegistrationDate = "openingRegistrationDate" - case _targetTeamCount = "targetTeamCount" case _waitingListLimit = "waitingListLimit" case _accountIsRequired = "accountIsRequired" case _licenseIsRequired = "licenseIsRequired" @@ -134,7 +132,7 @@ final class Tournament : ModelObject, Storable { } - 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, initialSeedRound: Int = 0, initialSeedCount: Int = 0, enableOnlineRegistration: Bool = false, registrationDateLimit: Date? = nil, openingRegistrationDate: Date? = nil, targetTeamCount: Int? = nil, waitingListLimit: Int? = nil, accountIsRequired: Bool = true, licenseIsRequired: Bool = true, minimumPlayerPerTeam: Int = 2, maximumPlayerPerTeam: Int = 2, information: String? = nil) { + 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, initialSeedRound: Int = 0, initialSeedCount: Int = 0, enableOnlineRegistration: Bool = false, registrationDateLimit: Date? = nil, openingRegistrationDate: Date? = nil, waitingListLimit: Int? = nil, accountIsRequired: Bool = true, licenseIsRequired: Bool = true, minimumPlayerPerTeam: Int = 2, maximumPlayerPerTeam: Int = 2, information: String? = nil) { self.event = event self.name = name self.startDate = startDate @@ -191,7 +189,6 @@ final class Tournament : ModelObject, Storable { self.enableOnlineRegistration = enableOnlineRegistration self.registrationDateLimit = registrationDateLimit self.openingRegistrationDate = openingRegistrationDate - self.targetTeamCount = targetTeamCount self.waitingListLimit = waitingListLimit self.accountIsRequired = accountIsRequired @@ -249,7 +246,6 @@ final class Tournament : ModelObject, Storable { enableOnlineRegistration = try container.decodeIfPresent(Bool.self, forKey: ._enableOnlineRegistration) ?? false registrationDateLimit = try container.decodeIfPresent(Date.self, forKey: ._registrationDateLimit) openingRegistrationDate = try container.decodeIfPresent(Date.self, forKey: ._openingRegistrationDate) - targetTeamCount = try container.decodeIfPresent(Int.self, forKey: ._targetTeamCount) waitingListLimit = try container.decodeIfPresent(Int.self, forKey: ._waitingListLimit) accountIsRequired = try container.decodeIfPresent(Bool.self, forKey: ._accountIsRequired) ?? true licenseIsRequired = try container.decodeIfPresent(Bool.self, forKey: ._licenseIsRequired) ?? true @@ -348,7 +344,6 @@ final class Tournament : ModelObject, Storable { try container.encode(enableOnlineRegistration, forKey: ._enableOnlineRegistration) try container.encode(registrationDateLimit, forKey: ._registrationDateLimit) try container.encode(openingRegistrationDate, forKey: ._openingRegistrationDate) - try container.encode(targetTeamCount, forKey: ._targetTeamCount) try container.encode(waitingListLimit, forKey: ._waitingListLimit) try container.encode(accountIsRequired, forKey: ._accountIsRequired) @@ -2490,19 +2485,16 @@ defer { } } - if let targetTeamCount = targetTeamCount { - // Get all team registrations excluding walk_outs - let currentTeamCount = unsortedTeamsWithoutWO().count - - if currentTeamCount >= targetTeamCount { - if let waitingListLimit = waitingListLimit { - let waitingListCount = currentTeamCount - targetTeamCount - if waitingListCount >= waitingListLimit { - return .waitingListFull - } + let currentTeamCount = unsortedTeamsWithoutWO().count + + if currentTeamCount >= teamCount { + if let waitingListLimit = waitingListLimit { + let waitingListCount = currentTeamCount - teamCount + if waitingListCount >= waitingListLimit { + return .waitingListFull } - return .waitingListPossible } + return .waitingListPossible } return .open diff --git a/PadelClub/Utils/PadelRule.swift b/PadelClub/Utils/PadelRule.swift index 07371b1..fc85147 100644 --- a/PadelClub/Utils/PadelRule.swift +++ b/PadelClub/Utils/PadelRule.swift @@ -369,6 +369,15 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable { var id: Int { self.rawValue } + func wildcardArePossible() -> Bool { + switch self { + case .p500, .p1000, .p1500, .p2000: + return true + default: + return false + } + } + func minimumPlayerRank(category: TournamentCategory, ageCategory: FederalTournamentAge) -> Int { switch self { case .p25: diff --git a/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift b/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift index 75f8134..7bd44eb 100644 --- a/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift +++ b/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift @@ -52,14 +52,9 @@ struct RegistrationSetupView: View { } // Target Team Count - if let targetTeamCount = tournament.targetTeamCount { - _targetTeamCount = .init(wrappedValue: targetTeamCount) - _targetTeamCountEnabled = .init(wrappedValue: true) - } else { - _targetTeamCount = .init(wrappedValue: tournament.teamCount) // Default value - _targetTeamCountEnabled = .init(wrappedValue: false) - } - + _targetTeamCount = .init(wrappedValue: tournament.teamCount) // Default value + _targetTeamCountEnabled = .init(wrappedValue: false) + // Waiting List Limit if let waitingListLimit = tournament.waitingListLimit { _waitingListLimit = .init(wrappedValue: waitingListLimit) @@ -289,9 +284,9 @@ struct RegistrationSetupView: View { } if targetTeamCountEnabled == false { - tournament.targetTeamCount = nil + tournament.teamCount = 24 } else { - tournament.targetTeamCount = targetTeamCount + tournament.teamCount = targetTeamCount } if waitingListLimitEnabled == false { diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index b89c2b5..93c95cc 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -77,6 +77,7 @@ struct TableStructureView: View { teamsPerGroupStage = structurePreset.teamsPerGroupStage() qualifiedPerGroupStage = structurePreset.qualifiedPerGroupStage() groupStageAdditionalQualified = 0 + buildWildcards = tournament.level.wildcardArePossible() } } @@ -223,7 +224,7 @@ struct TableStructureView: View { } } - if structurePreset.hasWildcards() { + if structurePreset.hasWildcards() && tournament.level.wildcardArePossible() { Section { Toggle("Avec wildcards", isOn: $buildWildcards) } footer: {