package com.multictrl.modules.business.service.impl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.multictrl.modules.business.dto.remote.debug.ESIMActivate;
import com.multictrl.modules.business.dto.remote.debug.ESIMOperatorSwitch;
import com.multictrl.modules.business.dto.remote.debug.RtkCalibration;
import com.multictrl.modules.business.dto.remote.debug.SIMSlotSwitch;
import com.multictrl.modules.business.service.DJIBaseService;
import com.multictrl.modules.business.service.DebugService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 远程调试接口
 *
 * @author Sdy
 * @since 1.0.0 2026/5/20
 */
@Service
@RequiredArgsConstructor
public class DebugServiceImpl implements DebugService {
    private final DJIBaseService djiBaseService;

    @Override
    public String eSIMOperatorSwitch(String dockSn, ESIMOperatorSwitch eSimOperatorSwitch) {
        JSONObject data = new JSONObject();
        data.set("imei", eSimOperatorSwitch.getImei());
        data.set("device_type", eSimOperatorSwitch.getDeviceType());
        data.set("esim_operator", eSimOperatorSwitch.getEsimOperator());
        return djiBaseService.executeAndReturnResult(dockSn, "esim_operator_switch", data);
    }

    @Override
    public String simSlotSwitch(String dockSn, SIMSlotSwitch simSlotSwitch) {
        JSONObject data = new JSONObject();
        data.set("imei", simSlotSwitch.getImei());
        data.set("device_type", simSlotSwitch.getDeviceType());
        data.set("sim_slot", simSlotSwitch.getSimSlot());
        return djiBaseService.executeAndReturnResult(dockSn, "sim_slot_switch", data);
    }

    @Override
    public String eSimActivate(String dockSn, ESIMActivate eSimActivate) {
        JSONObject data = new JSONObject();
        data.set("imei", eSimActivate.getImei());
        data.set("device_type", eSimActivate.getDeviceType());
        return djiBaseService.executeAndReturnResult(dockSn, "esim_activate", data);
    }

    @Override
    public String sdrWorkModeSwitch(String dockSn, Integer workMode) {
        JSONObject data = new JSONObject();
        data.set("link_workmode", workMode);
        return djiBaseService.executeAndReturnResult(dockSn, "sdr_workmode_switch", data);
    }

    @Override
    public String batteryStoreModeSwitch(String dockSn, Integer action) {
        JSONObject data = new JSONObject();
        data.set("action", action);
        return djiBaseService.executeAndReturnResult(dockSn, "battery_store_mode_switch", data);
    }

    @Override
    public String alarmStateSwitch(String dockSn, Integer action) {
        JSONObject data = new JSONObject();
        data.set("action", action);
        return djiBaseService.executeAndReturnResult(dockSn, "alarm_state_switch", data);
    }

    @Override
    public String airConditionerModeSwitch(String dockSn, Integer action) {
        JSONObject data = new JSONObject();
        data.set("action", action);
        return djiBaseService.executeAndReturnResult(dockSn, "air_conditioner_mode_switch", data);
    }

    @Override
    public String batteryMaintenanceSwitch(String dockSn, Integer action) {
        JSONObject data = new JSONObject();
        data.set("action", action);
        return djiBaseService.executeAndReturnResult(dockSn, "battery_maintenance_switch", data);
    }

    @Override
    public String rtkCalibration(String dockSn, RtkCalibration rtkCalibration) {
        JSONObject data = new JSONObject();
        data.set("devices", rtkCalibration.getDevices());
        return djiBaseService.executeAndReturnResult(dockSn, "rtk_calibration", data);
    }
}
