// // Employees.swift // EmployeeDirectory // // Created by Matt Bruce on 1/20/25. // import Foundation /// Wrapper JSON Class for the Employees public struct Employees: Codable { /// Array of Employees public var employees: [Employee] public let total: Int public let page: Int public let perPage: Int private enum CodingKeys: String, CodingKey { case employees case total case page case perPage = "per_page" } public init(employees: [Employee], total: Int = 0, page: Int = 1, perPage: Int = 10) { self.employees = employees self.total = total self.page = page self.perPage = perPage } public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.employees = try container.decode([Employee].self, forKey: .employees) self.total = try container.decodeIfPresent(Int.self, forKey: .total) ?? self.employees.count self.page = try container.decodeIfPresent(Int.self, forKey: .page) ?? 1 self.perPage = try container.decodeIfPresent(Int.self, forKey: .perPage) ?? self.total } }