import Foundation /// shoot 业务成功后的原始 data 回执,不假设或构造飞机、任务及飞行阶段字段。 struct DroneDockShootResponse: Decodable, Equatable, Sendable { /// 完整 data JSON;nil 表示统一客户端未提供 data,不补造 null 或空对象。 let dataJSON: String? /// 保留已格式化回执;业务成功但 data 缺失或为 null 时使用 nil。 init(dataJSON: String?) { self.dataJSON = dataJSON } /// 支持任意真实 JSON 值,保留未知结构、空数组、布尔值及原始字段类型。 init(from decoder: Decoder) throws { let raw = try DroneDockHomeJSONValue(from: decoder) let encoder = JSONEncoder() encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes] dataJSON = String(decoding: try encoder.encode(DroneDockShootJSONSnapshot(value: raw)), as: UTF8.self) } } /// 将现有 JSON 值解码结果格式化,完整保留 shoot 尚未约定的成功数据结构。 private struct DroneDockShootJSONSnapshot: Encodable { let value: DroneDockHomeJSONValue /// 按真实 JSON 类型编码,不推导任务身份或追加外层业务字段。 func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() switch value { case .object(let object): try container.encode(object.mapValues { DroneDockShootJSONSnapshot(value: $0) }) case .array(let array): try container.encode(array.map { DroneDockShootJSONSnapshot(value: $0) }) case .string(let text): try container.encode(text) case .number(let number): try container.encode(number) case .bool(let flag): try container.encode(flag) case .null: try container.encodeNil() } } }