package cn.iocoder.yudao.module.smartfactory.controller.admin.hik;

import cn.hutool.json.JSONObject;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.smartfactory.controller.admin.hik.vo.CameraOperateDTO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.hik.vo.CameraReplayDTO;
import cn.iocoder.yudao.module.smartfactory.service.hik.HikService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 工厂管理-工厂列表
 *
 * @author qun.xu
 */
@RestController
@RequestMapping("/smartfactory/hik")
@Tag(name = "海康接口")
public class HikController {

    @Resource
    private HikService hikService;

    @GetMapping("/getCameraUrl")
    @Operation(summary = "视频播放->查询播放地址")
    public CommonResult<String> getCameraUrl(String cameraCode) {
        String url = hikService.getPreviewUrlsApi(cameraCode, 0);
        return CommonResult.success(url);
    }

    @GetMapping("/replayUrl")
    @Operation(summary = "视频播放->回放流")
    public CommonResult<JSONObject> getReplayUrl(CameraReplayDTO cameraReplayDTO) {
        JSONObject replayUrl = hikService.getReplayUrl(cameraReplayDTO);
        return CommonResult.success(replayUrl);
    }

    @GetMapping("/operate")
    @Operation(summary = "视频->云台操作")
    public CommonResult<String> operate(CameraOperateDTO dto) {
        //判断操作权限
        Long cameraFactoryId = dto.getFactoryId();
//        Long userFactoryId = SecurityUtils.getFactoryId();
//        if (cameraFactoryId == null || userFactoryId == null) {
//            throw new ServiceException("没有权限操控该摄像头，请联系管理员");
//        }
//        if (SystemConfig.getFactoryCenterId() != userFactoryId && userFactoryId.longValue() != cameraFactoryId) {
//            throw new ServiceException("没有权限操控该摄像头，请联系管理员");
//        }
        String msg = hikService.operateCamera(dto);
        return CommonResult.success(msg);
    }

}

