package com.yn.bftl.thirdparty.modules.unionpay.controller.member;

import com.yn.bftl.common.modules.order.dto.IRefundDTO;
import com.yn.bftl.common.modules.order.enums.UnionpayAppTradeStatus;
import com.yn.bftl.thirdparty.modules.unionpay.dto.UnionpayAppOrderDTO;
import com.yn.bftl.thirdparty.modules.unionpay.service.UnionpayService;
import com.yn.bftl.thirdparty.modules.unionpay.vo.base.UnionpayResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Map;

/**
 * 银联控制层
 *
 * @author huabiao
 * @create 2022/8/29  13:55
 **/
@Validated
@Api(value = "UnionpayMemberController", tags = "用户端-银联")
@RestController
@RequestMapping("/member/unionpay")
public class UnionpayMemberController {

    @Resource
    private UnionpayService unionpayService;

    @ApiOperation(value = "银联-下单")
    @RequestMapping(value = "/app_order", method = RequestMethod.POST)
    public Map<String, Object> appOrder(@Valid @RequestBody UnionpayAppOrderDTO unionpayAppOrderDTO) {
        return unionpayService.appOrder(unionpayAppOrderDTO);
    }

    @ApiOperation("银联-订单交易查询")
    @GetMapping("/order_query")
    public UnionpayAppTradeStatus orderQuery(@NotBlank String unionpaySn) {
        return unionpayService.orderQuery(unionpaySn);
    }

    @ApiOperation(value = "银联-退款")
    @RequestMapping(value = "/refund", method = RequestMethod.POST)
    public String refund(@Valid @RequestBody IRefundDTO iRefundDTO) {
        return unionpayService.refund(iRefundDTO);
    }

    @ApiOperation("银联-退款查询")
    @GetMapping("/refund_query")
    public UnionpayResponseVO refundQuery(@NotBlank String refundMerOrderId) {
        return unionpayService.refundQuery(refundMerOrderId);
    }

    @ApiOperation("银联-订单关闭")
    @GetMapping("/order_close")
    public UnionpayResponseVO orderClose(@RequestParam Long paymentId) {
        return unionpayService.orderClose(paymentId);
    }
}
