package com.dbnt.kcscbackend.commonCode;

import com.dbnt.kcscbackend.commonCode.entity.TcCodeItem;
import com.dbnt.kcscbackend.commonCode.service.CommonCodeService;
import com.dbnt.kcscbackend.config.common.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@RequestMapping("/commonCode")
@Tag(name="CommonCodeController", description = "공통코드 컨트롤러")
public class CommonCodeController {

  private final CommonCodeService commonCodeService;

  @Operation(
      summary = "코드 아이템 목록 조회",
      description = "코드 아이템 목록 조회",
      tags = {"CommonCodeController"}
  )
  @ApiResponses(value = {
      @ApiResponse(responseCode = "200", description = "조회 성공"),
      @ApiResponse(responseCode = "403", description = "인가된 사용자가 아님")
  })
  @RequestMapping(method = RequestMethod.GET, value = "/code-item")
  public ResultVO getCodeItemList(TcCodeItem codeItem) throws Exception{
    ResultVO resultVO = new ResultVO();
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("codeList", commonCodeService.selectCodeItemList(codeItem.getGrpCd()));
    resultVO.setResult(resultMap);
    return resultVO;
  }
}
