import Foundation public struct SearchResponse: Codable, Sendable, Hashable, Equatable { public let count: Int public let offset: Int public let entities: [T] private enum CodingKeys: String, CodingKey, Hashable, Equatable { case count, offset } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) count = try container.decode(Int.self, forKey: .count) offset = try container.decode(Int.self, forKey: .offset) let dynamicContainer = try decoder.container(keyedBy: DynamicCodingKey.self) guard let key = DynamicCodingKey(stringValue: T.entityType.responseKey) else { throw DecodingError.dataCorrupted( DecodingError.Context( codingPath: decoder.codingPath, debugDescription: "Invalid response key for entity type" ) ) } entities = try dynamicContainer.decode([T].self, forKey: key) } }