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

import Foundation
import LeStorage
import SwiftUI

@Observable
class BaseCourt: SyncedModelObject, SyncedStorable {

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

    var id: String = Store.randomId()
    var index: Int = 0
    var club: String = ""
    var name: String? = nil
    var exitAllowed: Bool = false
    var indoor: Bool = false

    init(
        id: String = Store.randomId(),
        index: Int = 0,
        club: String = "",
        name: String? = nil,
        exitAllowed: Bool = false,
        indoor: Bool = false
    ) {
        super.init()
        self.id = id
        self.index = index
        self.club = club
        self.name = name
        self.exitAllowed = exitAllowed
        self.indoor = indoor
    }
    required public override init() {
        super.init()
    }

    enum CodingKeys: String, CodingKey {
        case _id = "id"
        case _index = "index"
        case _club = "club"
        case _name = "name"
        case _exitAllowed = "exitAllowed"
        case _indoor = "indoor"
    }

    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.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
        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.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)
        try super.encode(to: encoder)
    }

    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.index = court.index
        self.club = court.club
        self.name = court.name
        self.exitAllowed = court.exitAllowed
        self.indoor = court.indoor
    }

    static func relationships() -> [Relationship] {
        return [
            Relationship(type: Club.self, keyPath: \BaseCourt.club),
        ]
    }

}