import Foundation /// 朱工开始拍摄服务,只使用已创建并召唤的订单飞行任务身份。 protocol DroneDockStartShooting: Sendable { /// 提交一次开拍请求;调用方负责校验执行门禁并阻止重复提交。 @MainActor func startShooting(taskID: Int) async throws -> DroneDockStartShootResponse } /// start-shoot 合同适配;Debug 真实传输由统一客户端阻断,Release 按用户授权开放。 @MainActor final class DroneDockStartShootAPI: DroneDockStartShooting { private let client: APIClient /// 注入统一客户端,测试使用不会联网的本地模拟传输。 init(client: APIClient) { self.client = client } /// 仅 POST 任务 ID,不附带飞机、航线或未约定的模拟参数,也不自动重试。 func startShooting(taskID: Int) async throws -> DroneDockStartShootResponse { try Task.checkCancellation() guard taskID > 0 else { throw APIError.networkFailed("缺少有效拍摄任务 ID,请返回任务页确认") } let response: DroneDockStartShootResponse = try await client.send(APIRequest( method: .post, path: "/api/app/airport/start-shoot", body: StartShootBody(taskID: taskID) )) guard let returnedID = response.orderFlightTaskID, returnedID > 0, returnedID == taskID, response.orderFlightTask?.id == nil || response.orderFlightTask?.id == taskID else { throw APIError.decodeFailed("开始拍摄回执的任务身份缺失或不一致,请核对原任务状态") } return response } /// 开拍只提交订单飞行任务身份,不使用航线任务 ID。 private struct StartShootBody: Encodable { let taskID: Int /// 朱工开拍请求的 JSON 字段。 private enum CodingKeys: String, CodingKey { case taskID = "id" } } }