import Foundation /// start-shoot 的受理回执;不凭请求成功推断飞行、拍摄或素材已完成。 struct DroneDockStartShootResponse: Decodable, Equatable, Sendable { /// 文档约定的订单飞行任务 ID,API 必须核对其与请求一致。 let orderFlightTaskID: Int? /// 服务端提供的任务摘要,嵌套身份存在时同样参与核对。 let orderFlightTask: DroneDockShootingTaskIdentity? /// 当前任务锁定的飞机,不由客户端选择或覆盖。 let planeID: Int? /// 服务端任务 UUID,用于后续核对,不等于订单飞行任务 ID。 let taskUUID: String? /// 服务端返回的机场标识,仅保留已有值。 let airportSN: String? /// 服务端受理后的阶段文案,最新设备状态由 shooting 单次回查确认。 let ui: DroneDockShootingUI? /// 完整 data 的格式化 JSON,保留未知字段与原始类型供模拟联调展示。 let dataJSON: String /// 朱工开拍回执字段映射。 private enum CodingKeys: String, CodingKey { case orderFlightTaskID = "order_flight_task_id", orderFlightTask = "order_flight_task" case planeID = "plane_id", taskUUID = "task_uuid", airportSN = "airport_sn", ui } /// 仅解析响应实际提供的字段,不补造任务身份或成功状态。 init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) orderFlightTaskID = try container.decodeIfPresent(Int.self, forKey: .orderFlightTaskID) orderFlightTask = try container.decodeIfPresent(DroneDockShootingTaskIdentity.self, forKey: .orderFlightTask) planeID = try container.decodeIfPresent(Int.self, forKey: .planeID) taskUUID = try container.decodeIfPresent(String.self, forKey: .taskUUID) airportSN = try container.decodeIfPresent(String.self, forKey: .airportSN) ui = try container.decodeIfPresent(DroneDockShootingUI.self, forKey: .ui) let raw = try DroneDockHomeJSONValue(from: decoder) let encoder = JSONEncoder() encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes] dataJSON = String(decoding: try encoder.encode(DroneDockStartShootJSONSnapshot(value: raw)), as: UTF8.self) } } /// 将已有 JSON 值完整格式化,不给模拟响应添加后端未提供的字段。 private struct DroneDockStartShootJSONSnapshot: Encodable { let value: DroneDockHomeJSONValue /// 保留字符串、数字、布尔、空值和嵌套对象,不追加业务码包裹。 func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() switch value { case .object(let object): try container.encode(object.mapValues { DroneDockStartShootJSONSnapshot(value: $0) }) case .array(let array): try container.encode(array.map { DroneDockStartShootJSONSnapshot(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() } } }