// // FailedAPICall.swift // LeStorage // // Created by Laurent Morvillier on 31/05/2024. // import Foundation class FailedAPICall: SyncedModelObject, SyncedStorable { static func resourceName() -> String { return "failed-api-calls" } static func tokenExemptedMethods() -> [HTTPMethod] { return [] } static func relationships() -> [Relationship] { return [] } static var copyServerResponse: Bool = false override required init() { self.callId = "" self.type = "" self.apiCall = "" self.error = "" super.init() } var id: String = Store.randomId() /// The creation date of the call var date: Date = Date() /// The id of the API call var callId: String /// The type of the call var type: String /// The JSON representation of the API call var apiCall: String /// The server error var error: String /// The authentication header var authentication: String? init(callId: String, type: String, apiCall: String, error: String, authentication: String?) { self.callId = callId self.type = type self.apiCall = apiCall self.error = error self.authentication = authentication super.init() } // MARK: - Codable enum CodingKeys: String, CodingKey { case id case date case callId case type case apiCall case error case authentication } required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) id = try container.decode(String.self, forKey: .id) date = try container.decode(Date.self, forKey: .date) callId = try container.decode(String.self, forKey: .callId) type = try container.decode(String.self, forKey: .type) apiCall = try container.decode(String.self, forKey: .apiCall) error = try container.decode(String.self, forKey: .error) authentication = try container.decodeIfPresent(String.self, forKey: .authentication) try super.init(from: decoder) } override func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(date, forKey: .date) try container.encode(callId, forKey: .callId) try container.encode(type, forKey: .type) try container.encode(apiCall, forKey: .apiCall) try container.encode(error, forKey: .error) try container.encodeIfPresent(authentication, forKey: .authentication) try super.encode(to: encoder) } func copy(from other: any Storable) { guard let fac = other as? FailedAPICall else { return } self.date = fac.date self.callId = fac.callId self.type = fac.type self.apiCall = fac.apiCall self.error = fac.error self.authentication = fac.authentication } }