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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.loanmng.EasypayPaymentService;
import com.oqpo.api.service.loanmng.UnpaidMngService;
import com.oqpo.api.web.dto.request.loanmng.*;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.loanmng.EasypayPaymentCreateResponse;
import com.oqpo.api.web.dto.response.loanmng.EasypayPaymentResponse;
import com.oqpo.api.web.dto.response.loanmng.UnpaidMngInfoResponse;
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.*;
import springfox.documentation.annotations.ApiIgnore;

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

@Slf4j
@RestController
@RequestMapping("/api/easypay/payment")
@Api(tags = {"이지페이 결제 (EasypayPaymentController)"})
public class EasypayPaymentController {

    @Autowired
    private EasypayPaymentService easypayPaymentService;

    /**
     * 설명 : 이지페이 결제 생성
     *
     * @param userId
     * @param easypayPaymentCreateRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "이지페이 결제 생성")
    @PostMapping("/create")
    public ResponseEntity<EasypayPaymentCreateResponse> create(@ApiIgnore String userId, @RequestBody @Valid EasypayPaymentCreateRequest easypayPaymentCreateRequest) throws Exception {
        return ResponseEntity.ok(easypayPaymentService.createPayment(userId, easypayPaymentCreateRequest));
    }

    /**
     * 설명 : 이지페이 결제 요청
     *
     * @param userId
     * @param easypayPaymentRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "이지페이 결제 요청")
    @PostMapping("/request")
    public ResponseEntity<EasypayPaymentResponse> request(@ApiIgnore String userId, HttpServletRequest request,
                                                          @RequestBody @Valid EasypayPaymentRequest easypayPaymentRequest) throws Exception {
        return ResponseEntity.ok(easypayPaymentService.requestPayment(userId, request, easypayPaymentRequest));
    }

}
