package com.dbnt.kcscbackend.admin.config;

import com.dbnt.kcscbackend.admin.config.entity.TcCodeGrp;
import com.dbnt.kcscbackend.admin.config.service.AdminConfigService;
import com.dbnt.kcscbackend.config.common.BaseController;
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.http.MediaType;
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("/admin/config")
@Tag(name="AdminConfigController", description = "사이트관리 환결설정 메뉴 컨트롤러")
public class AdminConfigController extends BaseController {

  private final AdminConfigService adminConfigService;

  @Operation(
      summary = "기본코드 그룹 조회",
      description = "기본코드 그룹 조회",
      tags = {"AdminConfigController"}
  )
  @ApiResponses(value = {
      @ApiResponse(responseCode = "200", description = "조회 성공"),
      @ApiResponse(responseCode = "403", description = "인가된 사용자가 아님")
  })
  @RequestMapping(method = RequestMethod.GET, value = "/code-grp", consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResultVO getCodeGrp() throws Exception{
    ResultVO resultVO = new ResultVO();
    Map<String, Object> resultMap = new HashMap<>();
     resultMap.put("codeGrpList", adminConfigService.selectCodeGrpList());
    resultVO.setResult(resultMap);
    return resultVO;
  }

  @Operation(
      summary = "기본코드 아이템 조회",
      description = "기본코드 아이템 조회",
      tags = {"AdminConfigController"}
  )
  @ApiResponses(value = {
      @ApiResponse(responseCode = "200", description = "조회 성공"),
      @ApiResponse(responseCode = "403", description = "인가된 사용자가 아님")
  })
  @RequestMapping(method = RequestMethod.GET, value = "/code-item", consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResultVO getCodeItem(TcCodeGrp param) throws Exception{
    ResultVO resultVO = new ResultVO();
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("codeItemList", adminConfigService.selectCodeItemList(param.getGrpCd()));
    resultVO.setResult(resultMap);
    return resultVO;
  }
}
