package com.ruoyi.dj.mqtt.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.dj.mqtt.client.DJICloudMQTTClient;
import com.ruoyi.dj.mqtt.common.CommonFieldsVo;
import com.ruoyi.dj.mqtt.common.CommonResponse;
import com.ruoyi.dj.mqtt.domain.DrcVo;
import com.ruoyi.dj.mqtt.utils.CommonFieldsVoUtil;
import com.ruoyi.dj.mqtt.utils.ParseMethodUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

@Slf4j
@Component
public class DrcUpHandler {
    @Autowired
    private DJICloudMQTTClient djiCloudMQTTClient;

    public void handle(String matchedPart, String message) {
        log.info("drc up handler:{}", message);
        // 提取方法名
        DrcVo drcVo = CommonFieldsVoUtil.extractDrcVo(message);
        log.info("drc method:{}", drcVo.getMethod());
        if (drcVo.getMethod().equals("drone_control")) {
            log.info("drone_control");
        }
        CompletableFuture<String> responseFuture = djiCloudMQTTClient.getDrcResponseFutures(drcVo);
        if (responseFuture != null) {
            responseFuture.complete(message);
            djiCloudMQTTClient.completeDrcResponseFuture(drcVo, message);
        }
    }
}

