package com.takensoft.cms.prvcInqHstry.web;

import com.takensoft.cms.prvcInqHstry.service.PrvcInqHstryService;
import com.takensoft.cms.prvcInqHstry.vo.PrvcInqHstryVO;
import com.takensoft.common.message.MessageCode;
import com.takensoft.common.util.ResponseData;
import com.takensoft.common.util.ResponseUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.nio.charset.Charset;
import java.util.*;
/**
 * @author 박정하
 * @since 2024.05.22
 * @modification
 *     since    |    author    | description
 *  2024.05.22  |    박정하     | 최초 등록
 *
 * 개인정보 조회 이력 관련 Controller
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/admin/prvcInqHstry")
public class PrvcInqHstryController {
    private final PrvcInqHstryService prvcInqHstryService;
    private final ResponseUtil resUtil;

    /**
     * @author 박정하
     * @since 2024.05.22
     * @param prvcInqHstryVO
     * @return
     * @throws Exception
     *
     * 개인정보 조회 이력 등록
     */
    @PostMapping("/insertProc.json")
    public ResponseEntity<?> insertProc(HttpServletRequest request, @RequestBody PrvcInqHstryVO prvcInqHstryVO) throws Exception {
        int result = prvcInqHstryService.prvcInqHstryInsert(request, prvcInqHstryVO);

        // 응답 처리
        if(result > 0) {
            return resUtil.successRes(result, MessageCode.COMMON_SUCCESS);
        } else {
            return resUtil.errorRes(MessageCode.COMMON_INSERT_FAIL);
        }
    }

    /**
     * @author 박정하
     * @since 2024.05.27
     * @param params
     * @return
     * @throws Exception
     *
     * 개인정보 조회 이력 목록 조회
     */
    @PostMapping("/listProc.json")
    public ResponseEntity<?> listProc(@RequestBody HashMap<String, String> params) throws Exception {
        HashMap<String, Object> result = prvcInqHstryService.prvcInqHstryList(params);

        // 응답 처리
        return resUtil.successRes(result, MessageCode.COMMON_SUCCESS);
    }

    /**
     * @author 박정하
     * @since 2024.05.27
     * @param prvcInqHstryVO
     * @return
     * @throws Exception
     *
     * 개인정보 조회 이력 상세 조회
     */
    @PostMapping("/detailProc.json")
    public ResponseEntity<?> listProc(@RequestBody PrvcInqHstryVO prvcInqHstryVO) throws Exception {
        PrvcInqHstryVO result = prvcInqHstryService.prvcInqHstryDetail(prvcInqHstryVO.getInqHstryId());

        // 응답 처리
        return resUtil.successRes(result, MessageCode.COMMON_SUCCESS);
    }
}