package com.interplug.qcast.biz.community;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.interplug.qcast.biz.community.dto.BoardRequest;
import com.interplug.qcast.biz.community.dto.BoardResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/api/board")
@RequiredArgsConstructor
@Tag(name = "BoardController", description = "Community Board API")
public class BoardController {

  private final BoardService boardService;

  @Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 게시글 목록을 조회한다.")
  @GetMapping("/list")
  @ResponseStatus(HttpStatus.OK)
  public BoardResponse getBoardList(@ModelAttribute BoardRequest boardRequest) throws Exception {
    return boardService.getBoardList(boardRequest);
  }

  @Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 게시글 상세 정보를 조회한다.")
  @GetMapping("/detail")
  @ResponseStatus(HttpStatus.OK)
  public BoardResponse getBoardDetail(@ModelAttribute BoardRequest boardRequest) throws Exception {
    return boardService.getBoardDetail(boardRequest);
  }

  @Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 파일 다운로드를 진행한다.")
  @GetMapping("/file/download")
  @ResponseStatus(HttpStatus.OK)
  public void getFileDownload(HttpServletResponse response,
      @RequestParam(required = true) String encodeFileNo) throws Exception {
    boardService.getFileDownload(response, encodeFileNo);
  }

}
