package com.sz.admin.monitor.controller;

import com.sz.admin.monitor.pojo.dto.edgebox.AlgorithmTaskDTO;
import com.sz.admin.monitor.pojo.vo.watchful.WatchfulVO;
import com.sz.admin.monitor.service.IpChannelService;
import com.sz.admin.monitor.utils.AlgMediaConfigResponse;
import com.sz.core.common.entity.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: IpChannelController
 * Package: com.sz.admin.monitor.controller
 * Description: 通道相关操作的控制器
 */
@Tag(name = "通道相关操作")
@RestController
@RequestMapping("channel")
@RequiredArgsConstructor
@Profile({"dev", "local", "preview"})
public class IpChannelController {
    private final IpChannelService ipChannelService;
    // 视频预览接口
    @Operation(summary = "视频预览接口")
    @GetMapping("/preview")
    public ApiResult<String> preview(@RequestParam("id") Long id)  {
        String result = ipChannelService.preview(id);
        return ApiResult.success(result);
    }

    // 心跳保活接口
    @Operation(summary = "心跳保活接口")
    @GetMapping("/heartbeat")
    public ApiResult<?> heartbeat(@RequestParam("id") Long id,
                                  @RequestParam("uuid") String uuid) {
        ipChannelService.userHeartbeat(id,uuid);
        return ApiResult.success();
    }

    // 停止预览
    @Operation(summary = "停止预览")
    @GetMapping("/stopPreview")
    public ApiResult<Integer> stopPreview(@RequestParam("id") Long id,
                                          @RequestParam("uuid") String uuid)
    {
        Integer result = ipChannelService.stopPreview(id, uuid);
        return ApiResult.success(result);
    }

//    // 云台控制
//    @Operation(summary = "云台控制")
//    @GetMapping("/ptzControl")
//    public ApiResult<?> ptzControl(@RequestParam("channelId") int channelId,
//                                   @RequestParam("direction") Integer direction,
//                                   @RequestParam("speed") int speed,
//                                   @RequestParam("startFlag") int startFlag)
//    {
//        Object result = ipChannelService.ptzControl(channelId, direction, speed, startFlag);
//        return ApiResult.success(result);
//    }
    // 控制预置位
    @Operation(summary = "控制预置位")
    @GetMapping("/controlPreset")
    public ApiResult<?> controlPreset(@RequestParam("id") Long id,
                                      @RequestParam("ptzPresetCmd") int ptzPresetCmd,
                                      @RequestParam("dwPresetIndex") int dwPresetIndex,
                                      @RequestParam("pointName") String pointName,
                                      @RequestParam("isBasicPoint") int isBasicPoint)
    {
        Object result = ipChannelService.controlPreset(id, ptzPresetCmd, dwPresetIndex, pointName, isBasicPoint);
        return ApiResult.success(result);
    }

    // 控制云台守望
    @Operation(summary = "云台守望")
    @GetMapping("/sentinel")
    public ApiResult<?> ControlSentinel(@RequestParam("id") Long id,
                                        @RequestParam("openOrNo") Integer openOrNo,
                                        @RequestParam("watchTime") Integer watchTime,
                                        Integer presetIndex) {
        return ApiResult.success(ipChannelService.ControlSentinel(id, openOrNo, watchTime, presetIndex));
    }

    // 获取云台守望的参数
    @Operation(summary = "获取云台守望的参数")
    @GetMapping("/sentinel/get")
    public ApiResult<WatchfulVO> getWatchful(@RequestParam("id") Long id) {
        return ApiResult.success(ipChannelService.getWatchful(id));
    }
    // 配置算法任务
    @Operation(summary = "配置算法任务")
    @PostMapping("/config/alg")
    public ApiResult<AlgMediaConfigResponse> configAlg(@RequestBody AlgorithmTaskDTO algTaskConfigDto) {
        return ApiResult.success(ipChannelService.configAlg(algTaskConfigDto));
    }

}
