package com.zhongshu.card.server.core.controller.payment;


import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.devices.order.DeviceQrCodeParam;
import com.zhongshu.card.client.model.payment.WxOrderPrePayParam;
import com.zhongshu.card.server.core.service.payment.ExpenseFlowServiceImpl;
import com.zhongshu.card.server.core.service.payment.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("orderManager")
@Tag(name = "订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ExpenseFlowServiceImpl expenseFlowService;


    /**
     * 扫设备码下单
     */
    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "扫设备码下单（微信渠道）")
    @RequestMapping(value = {"cToBqrCodeBCreateOrder"}, method = {RequestMethod.POST})
    public ResultContent cToBqrCodeBCreateOrder(@RequestBody DeviceQrCodeParam param) {
        return orderService.wxCToBQrCodeCreateOrder(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "支付订单详情")
    @RequestMapping(value = {"getOrderPayDetail"}, method = {RequestMethod.POST})
    public ResultContent getOrderPayDetail(@RequestBody IDParam param) {
        return expenseFlowService.getOrderPayDetail(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "开始支付订单")
    @RequestMapping(value = {"payOrder"}, method = {RequestMethod.POST})
    public ResultContent payOrder(@RequestBody WxOrderPrePayParam param) {
        return expenseFlowService.initWxSurePaymentTypeOrderPay(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "取消订单")
    @RequestMapping(value = {"cancelOrder"}, method = {RequestMethod.POST})
    public ResultContent cancelOrder(@RequestBody IDParam param) {
        return expenseFlowService.cancelOrder(param.getId());
    }

}
