import Foundation struct Business: Identifiable, Codable, Hashable { let id: String let name: String let imageExtension: String? enum CodingKeys: String, CodingKey { case businessId = "BusinessID" case name = "Name" // Fallbacks for alternate API shapes case altId = "ID" case altName = "BusinessName" case imageExtension = "ImageExtension" } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) // BusinessID (from list endpoint) or ID (from other endpoints), always as String if let bid = try? container.decode(Int.self, forKey: .businessId) { id = String(bid) } else if let bid = try? container.decode(String.self, forKey: .businessId) { id = bid } else if let aid = try? container.decode(Int.self, forKey: .altId) { id = String(aid) } else if let aid = try? container.decode(String.self, forKey: .altId) { id = aid } else { id = "" } // Name (from list endpoint) or BusinessName (from other endpoints) name = (try? container.decode(String.self, forKey: .name)) ?? (try? container.decode(String.self, forKey: .altName)) ?? "" imageExtension = try? container.decode(String.self, forKey: .imageExtension) } func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .businessId) try container.encode(name, forKey: .name) try container.encodeIfPresent(imageExtension, forKey: .imageExtension) } var headerImageURL: URL? { guard let ext = imageExtension, !ext.isEmpty else { return nil } return URL(string: "\(APIConfig.imageBaseURL)/businesses/\(id)/header.\(ext)") } }