package cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.presentation;

import cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.service.KkoPayProcessService;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.PayController;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.model.PayApiRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
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.RestController;

import java.util.Map;

@Tag(name = "KkoPayProcessController")
@Slf4j
@RequiredArgsConstructor
@RestController
public class KkoPayProcessController implements PayController<ResponseEntity<PayApiRespDTO>, Map<String, Object>> {

    private final KkoPayProcessService kkoPayProcessService;

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "청구서링크 생성"
                            , value = "{\"billUid\":\"청구서UID\"}")
            })
    })
    @Operation(summary = "청구서링크 생성")
    @PostMapping(value = "/bill/kko/pay/gnrurl", produces = MediaType.APPLICATION_JSON_VALUE)
    @Override
    public ResponseEntity<PayApiRespDTO> gnrUrl(@RequestBody Map<String, Object> param) {
        return new ResponseEntity<PayApiRespDTO>(kkoPayProcessService.gnrUrl(param), HttpStatus.OK);
    }

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "결제정보 요청"
                            , value = "{\"data\":{\"biller_user_key\":\"빌러유저키\",\"biller_notice_key\":\"청구서UID\",\"user_birth\":\"19861128\",\"parameters\":{\"파라미터1\":\"8자이내값\"}}}")
            })
    })
    @Operation(summary = "납부(결제)정보 요청")
    @PostMapping(value = "/bill/kko/pay/notice", produces = MediaType.APPLICATION_JSON_VALUE)
    @Override
    public ResponseEntity<PayApiRespDTO> payNotice(@RequestBody Map<String, Object> param) {
        return new ResponseEntity<PayApiRespDTO>(kkoPayProcessService.payNotice(param), HttpStatus.OK);
    }

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "납부(결제)가능여부 확인"
                            , value = "{\"data\":{\"biller_user_key\":\"빌러유저키\",\"biller_notice_key\":\"청구서UID\",\"amount\":29000,\"parameters\":{\"파라미터1\":\"8자이내값\"}}}")
            })
    })
    @Operation(summary = "납부(결제)가능여부 확인")
    @PostMapping(value = "/bill/kko/pay/able", produces = MediaType.APPLICATION_JSON_VALUE)
    @Override
    public ResponseEntity<PayApiRespDTO> payAble(@RequestBody Map<String, Object> param) {
        return new ResponseEntity<PayApiRespDTO>(kkoPayProcessService.payAble(param), HttpStatus.OK);
    }

    @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
            @Content(mediaType = "application/json", examples = {
                    @ExampleObject(name = "Sample Example..."
                            , summary = "결과전달"
                            , value = "{\"data\":{\"biller_user_key\":\"빌러유저키\",\"biller_notice_key\":\"청구서UID\",\"parameters\":{\"파라미터1\":\"8자이내값\"},\"pay_by\":\"MONEY\",\"pay_type\":\"P\",\"pay_detail1\":\"\",\"pay_detail2\":\"\",\"amount\":20000,\"pay_amount\":20000,\"pay_fee_type\":\"BEFORE\",\"pay_fee\":150,\"pay_fee_tax\":15,\"paid_at\":\"20190220161656\",\"pay_id\":2748877}}")
            })
    })
    @Operation(summary = "납부(결제)결과 전달")
    @PostMapping(value = "/bill/kko/pay/result", produces = MediaType.APPLICATION_JSON_VALUE)
    @Override
    public ResponseEntity<PayApiRespDTO> payResult(@RequestBody Map<String, Object> param) {
        return new ResponseEntity<PayApiRespDTO>(kkoPayProcessService.payResult(param), HttpStatus.OK);
    }


    @Operation(summary = "결제취소")
    @PostMapping(value = "/bill/kko/pay/cancel", produces = MediaType.APPLICATION_JSON_VALUE)
    @Override
    public ResponseEntity<PayApiRespDTO> payCancel(Map<String, Object> param) {
        return new ResponseEntity<PayApiRespDTO>(kkoPayProcessService.payCancel(param), HttpStatus.OK);
    }
}
