package com.interplug.qcast.biz.file;

import com.interplug.qcast.biz.file.dto.FileRequest;
import com.interplug.qcast.biz.object.dto.*;
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.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/file")
@RequiredArgsConstructor
@Tag(name = "FileController", description = "파일 관련 API")
public class FileController {

  private final FileService fileService;

  @Operation(description = "파일을 다운로드 한다.")
  @PostMapping("/fileDownload")
  @ResponseStatus(HttpStatus.OK)
  public void fileDownload(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestBody FileRequest fileRequest)
      throws Exception {

    fileService.downloadFile(request, response, fileRequest);
  }

  @Operation(description = "모든 파일을 zip 다운로드 한다.")
  @PostMapping("/zipFileDownload")
  @ResponseStatus(HttpStatus.OK)
  public void allFileDownload(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestBody FileRequest fileRequest)
      throws Exception {

    fileService.downloadZipFile(request, response, fileRequest);
  }

  @Operation(description = "파일을 업로드 한다.")
  @PostMapping("/fileUpload")
  @ResponseStatus(HttpStatus.OK)
  public Integer fileUpload(
      HttpServletRequest request, HttpServletResponse response, FileRequest fileRequest)
      throws Exception {
    return fileService.fileUpload(request,fileRequest);
  }

  @Operation(description = "파일을 삭제 한다.")
  @PostMapping("/fileDelete")
  @ResponseStatus(HttpStatus.NO_CONTENT)
  public Integer fileDelete(@RequestBody FileRequest fileRequest) throws Exception {
    Integer resultCnt = fileService.deleteFile(fileRequest);
    return resultCnt;
  }
}
