// // Workout.swift // Werkout_ios // // Created by Trey Tartt on 6/14/23. // import Foundation struct Workout: Codable, Identifiable, Equatable { static func == (lhs: Workout, rhs: Workout) -> Bool { lhs.id == rhs.id } let id: Int let name: String let description: String? let supersets: [Superset]? let registeredUser: RegisteredUser? let femaleVideos, maleVideos, bothVideos: [String]? let muscles: [String]? let equipment: [String]? let exercise_count: Int? enum CodingKeys: String, CodingKey { case id, name, description, supersets, exercise_count, muscles, equipment case registeredUser = "registered_user" case maleVideos = "male_videos" case femaleVideos = "female_videos" case bothVideos = "both_videos" } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? "NA" self.description = try container.decodeIfPresent(String.self, forKey: .description) self.registeredUser = try container.decodeIfPresent(RegisteredUser.self, forKey: .registeredUser) self.id = try container.decode(Int.self, forKey: .id) self.femaleVideos = try container.decodeIfPresent([String].self, forKey: .femaleVideos) self.maleVideos = try container.decodeIfPresent([String].self, forKey: .maleVideos) self.bothVideos = try container.decodeIfPresent([String].self, forKey: .bothVideos) self.supersets = try container.decodeIfPresent([Superset].self, forKey: .supersets) self.equipment = try container.decodeIfPresent([String].self, forKey: .equipment) self.muscles = try container.decodeIfPresent([String].self, forKey: .muscles) self.exercise_count = try container.decodeIfPresent(Int.self, forKey: .exercise_count) } }