package cn.iocoder.yudao.module.remote.controller.admin.task;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.remote.service.task.RemoteTaskService;
import cn.iocoder.yudao.module.remote.util.IpUtils;
import cn.iocoder.yudao.module.system.api.remote.dto.RemoteExceptionTaskDetailDTO;
import cn.iocoder.yudao.module.system.api.remote.dto.RemoteRobotCameraDTO;
import cn.iocoder.yudao.module.system.api.remote.dto.RemoteTaskQueryDTO;
import cn.iocoder.yudao.module.system.api.remote.dto.RemoteTaskTransferDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 异常车辆列表")
@RestController
@RequestMapping("/remote/task")
@Validated
public class RemoteTaskController {

    @Autowired
    private RemoteTaskService remoteTaskService;


    @PostMapping("/getExceptionTaskDetail")
    @Operation(summary = "获取异常车辆任务列表")
    @PreAuthorize("@ss.hasPermission('remote:task:getExceptionTaskDetail')")
    public CommonResult<PageResult<RemoteExceptionTaskDetailDTO>> getExceptionTaskDetail(@RequestBody RemoteTaskQueryDTO remoteTaskQuery) {
        PageResult<RemoteExceptionTaskDetailDTO> list = remoteTaskService.getExceptionTaskDetail(remoteTaskQuery);
        return success(list);
    }

    @GetMapping("/getCarmeraByRobotNo")
    @Operation(summary = "查看环境--获取摄像头IP和账号")
    @PreAuthorize("@ss.hasPermission('remote:task:getExceptionTaskDetail')")
    public CommonResult<List<RemoteRobotCameraDTO>> getCarmeraByRobotNo(@RequestParam("robotNo") String robotNo) {
        List<RemoteRobotCameraDTO> list = remoteTaskService.getCarmeraByRobotNo(robotNo);
        return success(list);
    }


    @PostMapping("/transferTask")
    @Operation(summary = "任务转移")
    @PreAuthorize("@ss.hasPermission('remote:task:transferTask')")
    public CommonResult<Boolean> remoteTransferTask(@RequestBody RemoteTaskTransferDTO remoteTaskTransfer, HttpServletRequest request) {
        String remoteIp = IpUtils.getIp(request);
        remoteTaskTransfer.setRemoteIp(remoteIp);
        remoteTaskService.remoteTransferTask(remoteTaskTransfer);
        return success(true);
    }









}
