package com.unis.mobileInfo.modular.videoSurveillance.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.unis.common.pojo.CommonResult;
import com.unis.equipmentOnlineRateAssessment.modular.hk.constant.HkProtocolEnum;
import com.unis.equipmentOnlineRateAssessment.modular.hk.dto.req.PreviewReqDTO;
import com.unis.equipmentOnlineRateAssessment.modular.hk.dto.res.PreviewResDTO;
import com.unis.equipmentOnlineRateAssessment.modular.hk.service.HkService;
import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.entity.MonitorCamera;
import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.service.MonitorCameraService;
import com.unis.equipmentOnlineRateAssessment.modular.monitorNvr.service.MonitorNvrService;
import com.unis.equipmentOnlineRateAssessment.modular.monitorNvr.utils.ParameterUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 移动端 视频预览
 */
@Api(tags = "移动端 视频预览")
@ApiSupport(author = "UNIS_TEAM", order = 1)
@RestController
@Validated
public class MobileEndPreviewController {

    @Resource
    private HkService hkService;

    @Resource
    private MonitorCameraService monitorCameraService;

    @Resource
    private MonitorNvrService monitorNvrService;


    /**
     * 摄像头预览
     * 获取该库的 所有视频信息
     * @return
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("*视频预览")
    @GetMapping("/client/c/previewPlayback/getPreview")
    public CommonResult<List<PreviewResDTO>> getPreview(Integer orgId) {
        List<PreviewResDTO> returnList = new ArrayList<>();
        //根据orgId 获取摄像头
        List<MonitorCamera> monitorCameraList = monitorCameraService.getlistByOrgId(orgId);

        for (MonitorCamera monitorCamera:monitorCameraList){
            PreviewReqDTO previewReqDTO = new PreviewReqDTO(monitorCamera.getCameraIndexCode(), HkProtocolEnum.WS);
            PreviewResDTO previewResDTO = hkService.previewURLs(previewReqDTO);
            returnList.add(previewResDTO);
        }
        return CommonResult.data(returnList);
    }


    /**
     * shine
     * @param orgId
     * @return
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("*查找要录像的NVR信息")
    @GetMapping("/client/c/camera/getNVRVideo")
    public CommonResult<List<Map<String,Object>>> getNVRVideo(Integer orgId) {
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId.toString());
        List<Map<String,Object>> list = monitorNvrService.selectByNVRDates(map);
        return CommonResult.data(ParameterUtil.slashCapitals(list));
    }

    /**
     * shine
     * @param orgId
     * @return
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("*摄像头 在线离线个数")
    @GetMapping("/client/c/camera/getCameraNumber")
    public CommonResult<Map<String,Object>> getCameraNumber(Integer orgId) {
        return CommonResult.data(monitorCameraService.getCameraNumber(orgId));
    }

}
