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

import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig;
import cn.skcks.docking.gb28181.wvp.service.download.DownloadService;
import cn.skcks.docking.gb28181.wvp.service.gb28181.Gb28181DownloadService;
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 org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@Tag(name = "下载")
@RestController
@RequestMapping("/download")
public class DownloadController {
    private final DownloadService downloadService;
    private final Gb28181DownloadService gb28181DownloadService;

    @Bean
    public GroupedOpenApi downloadApi() {
        return SwaggerConfig.api("DownloadApi", "/download");
    }

    @Operation(summary = "下载代理")
    @RequestMapping(method = RequestMethod.HEAD, value = "/proxy")
    public void downloadProxyHeader(HttpServletRequest request, HttpServletResponse response, @RequestParam String url) {
        downloadService.header(request, response, url);
    }

    @Operation(summary = "下载代理")
    @GetMapping("/proxy")
    public void downloadProxy(HttpServletRequest request, HttpServletResponse response, @RequestParam String url) {
        downloadService.download(request, response, url);
    }
}
