You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
4.1 KiB
109 lines
4.1 KiB
// 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()
|
|
let dateString = try container.decode(String.self, forKey: ._lastUpdate)
|
|
self.lastUpdate = Date.iso8601FractionalFormatter.date(from: dateString) ?? 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(Date.iso8601FractionalFormatter.string(from: 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
|
|
}
|
|
static func relationships() -> [Relationship] {
|
|
return [
|
|
Relationship(type: Match.self, keyPath: \BaseTeamScore.match),
|
|
Relationship(type: TeamRegistration.self, keyPath: \BaseTeamScore.teamRegistration),
|
|
]
|
|
}
|
|
|
|
} |