package com.cico.nest.lcdp.boot.core.qxsd.adapter.web;

import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.request.TunnelCameraRequest;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.TunnelEquipmentMapper;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.TunnelEquipmentDO;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.hk.HkVideoMapper;
import com.cico.nest.lcdp.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Comparator;
import java.util.List;

/**
 * @author zws
 * @date 2024/9/2
 */

@Tag(name = "管理后台 - 视频接口")
@RestController
@RequestMapping("/qxsd/video")
@Validated
public class VideoController {
    @Resource
    private TunnelEquipmentMapper tunnelEquipmentMapper;
    @Resource
    HkVideoMapper hkVideoMapper;

    @Operation(summary = "隧道摄像机信息")
    @PostMapping("/tunnelCamera")
    public CommonResult<List<TunnelEquipmentDO>> getTunnelCamera(@RequestBody TunnelCameraRequest request){
        List<TunnelEquipmentDO> tunnelEquipmentDOS = tunnelEquipmentMapper
                .facilityCamera(request.getFacilityId(), request.getUplinkDownlinkRoad());
        tunnelEquipmentDOS = tunnelEquipmentDOS.stream().sorted((Comparator.comparing(TunnelEquipmentDO::getEquipmentStation))).toList();
        return CommonResult.success(tunnelEquipmentDOS);
    }

    @Operation(summary = "视频预览地址")
    @GetMapping("/cameraPreviewURLs")
    @Parameters({
            @Parameter(name = "cameraIndexCode", description = "摄像机编码", required = true)
    })
    public String cameraPreviewURLs(@RequestParam("cameraIndexCode") String cameraIndexCode){
        return hkVideoMapper.getCameraPreviewURLs(cameraIndexCode);
    }
    @Operation(summary = "视频回放地址")
    @GetMapping("/getPlaybackURL")
    public String getPlaybackURL(String cameraIndexCode,String startTime, String endTime) {
        return hkVideoMapper.getPlaybackURLs(cameraIndexCode,startTime,endTime);
    }


    @Operation(summary = "获取摄像机indexCode")
    @GetMapping("/getCameraIndexCode")
    public String getCameraIndexCode(@RequestParam("treeCode") String treeCode,@RequestParam("regionIndexCode")String regionIndexCode){
        return hkVideoMapper.getCameraIndexCode(treeCode,regionIndexCode);
    }

}
