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

import Foundation
import LeStorage
import SwiftUI

@Observable
class BaseDateInterval: SyncedModelObject, SyncedStorable {

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

    var id: String = Store.randomId()
    var event: String = ""
    var courtIndex: Int = 0
    var startDate: Date = Date()
    var endDate: Date = Date()

    init(
        id: String = Store.randomId(),
        event: String = "",
        courtIndex: Int = 0,
        startDate: Date = Date(),
        endDate: Date = Date()
    ) {
        super.init()
        self.id = id
        self.event = event
        self.courtIndex = courtIndex
        self.startDate = startDate
        self.endDate = endDate
    }
    required public override init() {
        super.init()
    }

    enum CodingKeys: String, CodingKey {
        case _id = "id"
        case _event = "event"
        case _courtIndex = "courtIndex"
        case _startDate = "startDate"
        case _endDate = "endDate"
    }

    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.event = try container.decodeIfPresent(String.self, forKey: ._event) ?? ""
        self.courtIndex = try container.decodeIfPresent(Int.self, forKey: ._courtIndex) ?? 0
        self.startDate = try container.decodeIfPresent(Date.self, forKey: ._startDate) ?? Date()
        self.endDate = try container.decodeIfPresent(Date.self, forKey: ._endDate) ?? Date()
        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.event, forKey: ._event)
        try container.encode(self.courtIndex, forKey: ._courtIndex)
        try container.encode(self.startDate, forKey: ._startDate)
        try container.encode(self.endDate, forKey: ._endDate)
        try super.encode(to: encoder)
    }

    func copy(from other: any Storable) {
        guard let dateinterval = other as? BaseDateInterval else { return }
        self.id = dateinterval.id
        self.event = dateinterval.event
        self.courtIndex = dateinterval.courtIndex
        self.startDate = dateinterval.startDate
        self.endDate = dateinterval.endDate
    }

    static func relationships() -> [Relationship] {
        return []
    }

}