package cn.skcks.docking.gb28181.wvp.api.video;

import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
import cn.skcks.docking.gb28181.wvp.api.video.dto.VideoReq;
import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig;
import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig;
import cn.skcks.docking.gb28181.wvp.service.gb28181.Gb28181DownloadService;
import cn.skcks.docking.gb28181.wvp.service.video.VideoService;
import cn.skcks.docking.gb28181.wvp.service.wvp.WvpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@Tag(name = "视频api")
@Controller
@RequestMapping("/video")
@RequiredArgsConstructor
public class VideoController {
    private final ZlmMediaConfig config;
    private final VideoService videoService;
    private final WvpService wvpService;

    private final WvpProxyConfig proxyConfig;

    private final Gb28181DownloadService gb28181DownloadService;

    @Bean
    public GroupedOpenApi videoApi() {
        return SwaggerConfig.api("VideoApi", "/video");
    }

    @Operation(summary = "获取视频 (目前仅供测试)")
    @GetMapping(produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @ResponseBody
    public void video(HttpServletRequest request, HttpServletResponse response, @ParameterObject VideoReq req) {
        if(proxyConfig.getEnable()){
          wvpService.video(request,response,req.getDeviceCode(), req.getStartTime(), req.getEndTime());
        } else {
            gb28181DownloadService.video(request,response,req.getDeviceCode(), req.getStartTime(), req.getEndTime());
        }
    }
}
