package com.oqpo.api.web.controller.sttlmng;

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.sttlmng.KiccPayMngService;
import com.oqpo.api.service.sttlmng.SttlStateService;
import com.oqpo.api.web.dto.request.sttlmng.KiccPayCancelRequest;
import com.oqpo.api.web.dto.request.sttlmng.KiccPayGridRequest;
import com.oqpo.api.web.dto.request.sttlmng.SttlConfirmRequest;
import com.oqpo.api.web.dto.request.sttlmng.SttlStateGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/kicc/pay")
@Api(tags = {"KICC 거래내역 관리 (KiccPayMngController)"})
public class KiccPayMngController {

    @Autowired
    private KiccPayMngService kiccPayMngService;

    /**
     * 설명 : 거래내역 그리드 리스트
     *
     * @param kiccPayGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "거내내역 그리드 리스트")
    @PostMapping("/detail-grid-list")
    public ResponseEntity<GridResponse> detailGridList(@RequestBody @Valid KiccPayGridRequest kiccPayGridRequest) throws Exception {
        return ResponseEntity.ok(kiccPayMngService.selectKiccPayGridList(kiccPayGridRequest.getSBrandId(), kiccPayGridRequest.getSStoreId(),
                kiccPayGridRequest.getSTranType(), kiccPayGridRequest.getSAuthNo(),
                kiccPayGridRequest.getFromDt(), kiccPayGridRequest.getToDt(), kiccPayGridRequest.toDTO(kiccPayGridRequest)));
    }

    /**
     * 설명 : 거래 취소 처리
     *
     * @param userId
     * @param kiccPayCancelRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "거래 취소 처리")
    @PostMapping("/cancel-proc")
    public ResponseEntity<SaveResponse> procCancel(@ApiIgnore String userId, HttpServletRequest request,
                                                   @RequestBody @Valid KiccPayCancelRequest kiccPayCancelRequest) throws Exception {
        kiccPayMngService.procCancel(userId, request, kiccPayCancelRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

}
