// Generated by SwiftModelGenerator
// Do not modify this file manually

import Foundation
import LeStorage
import SwiftUI

@Observable
class BaseMatchScheduler: BaseModelObject, Storable {

    static func resourceName() -> String { return "match-scheduler" }
    static func tokenExemptedMethods() -> [HTTPMethod] { return [] }

    var id: String = Store.randomId()
    var tournament: String = ""
    var timeDifferenceLimit: Int = 5
    var loserBracketRotationDifference: Int = 0
    var upperBracketRotationDifference: Int = 1
    var accountUpperBracketBreakTime: Bool = true
    var accountLoserBracketBreakTime: Bool = false
    var randomizeCourts: Bool = true
    var rotationDifferenceIsImportant: Bool = false
    var shouldHandleUpperRoundSlice: Bool = false
    var shouldEndRoundBeforeStartingNext: Bool = true
    var groupStageChunkCount: Int? = nil
    var overrideCourtsUnavailability: Bool = false
    var shouldTryToFillUpCourtsAvailable: Bool = false
    var courtsAvailable: Set<Int> = Set<Int>()
    var simultaneousStart: Bool = true

    init(
        id: String = Store.randomId(),
        tournament: String = "",
        timeDifferenceLimit: Int = 5,
        loserBracketRotationDifference: Int = 0,
        upperBracketRotationDifference: Int = 1,
        accountUpperBracketBreakTime: Bool = true,
        accountLoserBracketBreakTime: Bool = false,
        randomizeCourts: Bool = true,
        rotationDifferenceIsImportant: Bool = false,
        shouldHandleUpperRoundSlice: Bool = false,
        shouldEndRoundBeforeStartingNext: Bool = true,
        groupStageChunkCount: Int? = nil,
        overrideCourtsUnavailability: Bool = false,
        shouldTryToFillUpCourtsAvailable: Bool = false,
        courtsAvailable: Set<Int> = Set<Int>(),
        simultaneousStart: Bool = true
    ) {
        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
        self.courtsAvailable = courtsAvailable
        self.simultaneousStart = simultaneousStart
    }
    required public override init() {
        super.init()
    }

    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"
        case _courtsAvailable = "courtsAvailable"
        case _simultaneousStart = "simultaneousStart"
    }

    required init(from decoder: Decoder) throws {
        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) ?? 5
        self.loserBracketRotationDifference = try container.decodeIfPresent(Int.self, forKey: ._loserBracketRotationDifference) ?? 0
        self.upperBracketRotationDifference = try container.decodeIfPresent(Int.self, forKey: ._upperBracketRotationDifference) ?? 1
        self.accountUpperBracketBreakTime = try container.decodeIfPresent(Bool.self, forKey: ._accountUpperBracketBreakTime) ?? true
        self.accountLoserBracketBreakTime = try container.decodeIfPresent(Bool.self, forKey: ._accountLoserBracketBreakTime) ?? false
        self.randomizeCourts = try container.decodeIfPresent(Bool.self, forKey: ._randomizeCourts) ?? true
        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) ?? true
        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
        self.courtsAvailable = try container.decodeIfPresent(Set<Int>.self, forKey: ._courtsAvailable) ?? Set<Int>()
        self.simultaneousStart = try container.decodeIfPresent(Bool.self, forKey: ._simultaneousStart) ?? true
        try super.init(from: decoder)
    }

    override 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)
        try container.encode(self.courtsAvailable, forKey: ._courtsAvailable)
        try container.encode(self.simultaneousStart, forKey: ._simultaneousStart)
        try super.encode(to: encoder)
    }

    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
        self.courtsAvailable = matchscheduler.courtsAvailable
        self.simultaneousStart = matchscheduler.simultaneousStart
    }

    static func relationships() -> [Relationship] {
        return [
            Relationship(type: Tournament.self, keyPath: \BaseMatchScheduler.tournament),
        ]
    }

}