package com.tuoheng.admin.tzhl.service.task;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.tzhl.constant.TZHLConstant;
import com.tuoheng.admin.tzhl.response.TZHLAirportLineResponse;
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class FlightTaskService {

    @Autowired
    @Qualifier("restTemplate")
    private RestTemplate restTemplate;

    @Autowired
    private CallTianYiPlatformService callTianYiPlatformService;

    public JsonResult flightTask(Inspection inspection) {
        String apiPath = TZHLConstant.TIAN_YI_API_WAYLINE_FLIGHT_TASKS;
        JSONObject jsonObject = this.buildJSONObject(inspection);
        String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject);
        return JsonResult.success(dataJson);
    }

    private JSONObject buildJSONObject(Inspection inspection) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("method", "flighttask_prepare");       // 默认值 flighttask_prepare
        jsonObject.put("sn", inspection.getSn());             // 机库序列号
        jsonObject.put("recordId", inspection.getRecordId()); // 飞行计划Id
        return jsonObject;
    }

}
