package com.multictrl.modules.business.controller;

import com.multictrl.common.annotation.ApiOrder;
import com.multictrl.common.annotation.LogOperation;
import com.multictrl.common.utils.Result;
import com.multictrl.modules.business.service.DJIBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 远程调试
 *
 * @author Sdy
 * @since 1.0.0 2026/4/24
 */
@RestController
@RequestMapping("business/debug")
@Tag(name = "远程调试", description = "远程调试为在调试的作业流中实现无人值守，即让作业人员无需到现场，在云端就可以下发命令到设备端，" +
        "进行设备的远程排障。远程调试命令可分为命令（cmd）和任务（job）。命令（cmd）一般指命令下发后，设备能即刻回复的行为，而任务（job）" +
        "为任务下发后，设备需要持续动作的行为。")
@ApiOrder(3)
@RequiredArgsConstructor
public class DebugController {
    private final DJIBaseService debugService;

    @Operation(summary = "调试模式开启")
    @GetMapping("/debugModeOpen/{dockSn}")
    @LogOperation("调试模式开启")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> debugModeOpen(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "debug_mode_open"));
    }

    @Operation(summary = "调试模式关闭")
    @GetMapping("/debugModeClose/{dockSn}")
    @LogOperation("调试模式关闭")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> debugModeClose(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "debug_mode_close"));
    }

    @Operation(summary = "强制关舱盖")
    @GetMapping("/coverForceClose/{dockSn}")
    @LogOperation("强制关舱盖")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> coverForceClose(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "cover_force_close"));
    }

    @Operation(summary = "打开舱盖")
    @GetMapping("/coverOpen/{dockSn}")
    @LogOperation("打开舱盖")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> coverOpen(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "cover_open"));
    }

    @Operation(summary = "关闭舱盖")
    @GetMapping("/coverClose/{dockSn}")
    @LogOperation("关闭舱盖")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> coverClose(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "cover_close"));
    }

    @Operation(summary = "飞行器开机")
    @GetMapping("/droneOpen/{dockSn}")
    @LogOperation("飞行器开机")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> droneOpen(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "drone_open"));
    }

    @Operation(summary = "飞行器关机")
    @GetMapping("/droneClose/{dockSn}")
    @LogOperation("飞行器关机")
    @RequiresPermissions("bus:debug:operation")
    public Result<Object> droneClose(@PathVariable String dockSn) {
        return new Result<>().ok(debugService.executeAndReturnResult(dockSn, "drone_close"));
    }
}
