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

import Foundation
import LeStorage
import SwiftUI

@Observable
class BasePlayerRegistration: SyncedModelObject, SyncedStorable {

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

    var id: String = Store.randomId()
    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: PlayerRegistration.PlayerDataSource? = nil
    var hasArrived: Bool = false
    var coach: Bool = false
    var captain: Bool = false
    var registeredOnline: Bool = false

    init(
        id: String = Store.randomId(),
        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: PlayerRegistration.PlayerDataSource? = nil,
        hasArrived: Bool = false,
        coach: Bool = false,
        captain: Bool = false,
        registeredOnline: Bool = false
    ) {
        super.init()
        self.id = id
        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.coach = coach
        self.captain = captain
        self.registeredOnline = registeredOnline
    }
    required public override init() {
        super.init()
    }

    enum CodingKeys: String, CodingKey {
        case _id = "id"
        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 _coach = "coach"
        case _captain = "captain"
        case _registeredOnline = "registeredOnline"
    }

    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.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(PlayerRegistration.PlayerDataSource.self, forKey: ._source) ?? nil
        self.hasArrived = try container.decodeIfPresent(Bool.self, forKey: ._hasArrived) ?? false
        self.coach = try container.decodeIfPresent(Bool.self, forKey: ._coach) ?? false
        self.captain = try container.decodeIfPresent(Bool.self, forKey: ._captain) ?? false
        self.registeredOnline = try container.decodeIfPresent(Bool.self, forKey: ._registeredOnline) ?? false
        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.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.coach, forKey: ._coach)
        try container.encode(self.captain, forKey: ._captain)
        try container.encode(self.registeredOnline, forKey: ._registeredOnline)
        try super.encode(to: encoder)
    }

    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.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.coach = playerregistration.coach
        self.captain = playerregistration.captain
        self.registeredOnline = playerregistration.registeredOnline
    }

    static func relationships() -> [Relationship] {
        return [
            Relationship(type: TeamRegistration.self, keyPath: \BasePlayerRegistration.teamRegistration),
        ]
    }

}