package com.zswl.cloud.springBtach.server.core.controller;

import com.github.microservice.auth.client.constant.AuthConstant;
import com.github.microservice.auth.client.content.ResultContent;
import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.payment.client.model.order.AdminSeachOrderModel;
import com.zhongshu.payment.client.model.order.ApplicantRefundParamModel;
import com.zhongshu.payment.client.model.order.v2.ApplicantRefundParam2Model;
import com.zhongshu.payment.client.model.order.v2.RefundParam2Model;
import com.zhongshu.payment.client.model.order.v2.TransferModel;
import com.zhongshu.payment.client.model.order.v2.WithdrawRequestModel;
import com.zhongshu.payment.client.model.payment.CloseResponsetModel;
import com.zhongshu.payment.client.model.payment.CreateResponseModel;
import com.zhongshu.payment.client.model.payment.QueryRequestModel;
import com.zhongshu.payment.client.model.payment.zswl.CreatePaymentModel;
import com.zhongshu.payment.client.model.payment.zswl.SyncInformModel;
import com.zswl.cloud.springBtach.server.core.model.SubOrderModel;
import com.zswl.cloud.springBtach.server.core.service.PaymentService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Log4j2
@RestController
@RequestMapping("pay")
public class PaymentController {


    @Autowired
    PaymentService paymentServer;


    @ApiOperation("创建支付订单")
    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "creatPayOrder", method = RequestMethod.POST)
    public ResultContent<CreateResponseModel> creatPayOrder(@RequestBody CreatePaymentModel createPaymentModel) {
        return paymentServer.creatPayOrder(createPaymentModel);
    }


    @ApiOperation("查询订单状态")
    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "query/{orderNo}", method = RequestMethod.GET)
    public ResultContent<QueryRequestModel> query(@PathVariable("orderNo") String orderNo) {
        return paymentServer.query(orderNo);
    }


    @ApiOperation("退款申请")
    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "applicantRefund", method = RequestMethod.POST)
    public ResultContent refund(@RequestBody @Valid ApplicantRefundParamModel applicantRefundParamModel) {
        ApplicantRefundParam2Model applicantRefundParam2Model = new ApplicantRefundParam2Model();
        BeanUtils.copyProperties(applicantRefundParamModel, applicantRefundParam2Model);

        return paymentServer.applicantRefund(applicantRefundParam2Model);
    }


    @ApiOperation("取消退款")
    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "unRefund", method = RequestMethod.POST)
    public ResultContent unRefund(@RequestBody @Valid ApplicantRefundParamModel applicantRefundParamModel) {
        ApplicantRefundParam2Model applicantRefundParam2Model = new ApplicantRefundParam2Model();
        BeanUtils.copyProperties(applicantRefundParamModel, applicantRefundParam2Model);
        return paymentServer.unRefund(applicantRefundParam2Model);
    }


    @ApiOperation("退款审核")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "auditRefund", method = RequestMethod.POST)
    public ResultContent auditRefund(@RequestBody @Valid RefundParam2Model refundParam2Model) {
        return paymentServer.auditRefund(refundParam2Model);
    }


    @ApiOperation("关闭订单")
    @ResourceAuth(value = "user", type = AuthType.User)
    @RequestMapping(value = "close/{orderNo}", method = RequestMethod.GET)
    public ResultContent<CloseResponsetModel> close(@PathVariable("orderNo") String orderNo) {
        return paymentServer.close(orderNo);
    }

    @ApiOperation("获取分账信息")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "transfer/{orderNo}", method = RequestMethod.GET)
    public ResultContent<TransferModel> transfer(@PathVariable("orderNo") String orderNo) {
        return paymentServer.transfer(orderNo);
    }

    @ApiOperation("平台收入明细获取分账信息")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "transfer/list", method = RequestMethod.POST)
    public ResultContent<TransferModel> transferList(@RequestBody @Valid AdminSeachOrderModel adminSeachOrderModel) {
        return paymentServer.transferList(adminSeachOrderModel);
    }


    @ApiOperation("查询 额度信息")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "account/getDetail", method = RequestMethod.GET)
    public ResultContent getDetail() {
        return paymentServer.getDetail();
    }

    @ApiOperation("平台查询 额度信息")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @RequestMapping(value = "account/platformDetail", method = RequestMethod.GET)
    public ResultContent platformDetail() {
        return paymentServer.platformDetail();
    }


    @ApiOperation("店铺_提现按钮")
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "account/withdrawals", method = RequestMethod.GET)
    public ResultContent withdrawals() {
        return paymentServer.withdrawals();
    }

    @ApiOperation("平台_提现按钮")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @RequestMapping(value = "account/withdrawalsPlatform", method = RequestMethod.GET)
    public ResultContent withdrawalsPlatform() {
        return paymentServer.withdrawalsPlatform();
    }

    @ApiOperation("店铺_提现订单列表")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "account/withdrawals/list", method = RequestMethod.POST)
    public ResultContent withdrawalsList(@RequestBody WithdrawRequestModel withdrawRequestModel) {
        return paymentServer.withdrawalsList(withdrawRequestModel);
    }
    @ApiOperation("店铺_提现订单列表")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @RequestMapping(value = "account/withdrawals/platform/list", method = RequestMethod.POST)
    public ResultContent withdrawalsPlatformList(@RequestBody WithdrawRequestModel withdrawRequestModel) {
        return paymentServer.withdrawalsPlatformList(withdrawRequestModel);
    }

    @ApiOperation("店铺_分账明细列表")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @ResourceAuth(value = "admin", type = AuthType.Enterprise)
    @ResourceAuth(value = "admin", type = AuthType.Project)
    @RequestMapping(value = "account/withdrawals/detailList", method = RequestMethod.POST)
    public ResultContent withdrawalsDetailList(@RequestBody WithdrawRequestModel withdrawRequestModel) {
        return paymentServer.withdrawalsDetailList(withdrawRequestModel);
    }

    @ApiOperation("后台_确认分账")
    @ResourceAuth(value = AuthConstant.SuperAdmin, type = AuthType.Platform)
    @RequestMapping(value = "subOrdersConfirm", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultContent subOrdersConfirm(@RequestBody SubOrderModel subOrderModel) {
        return paymentServer.subOrdersConfirm(subOrderModel.getGoodId(), subOrderModel.getUseShop());
    }
    @ApiOperation("异步通知")
    @RequestMapping(value = "sync", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public String sync(@RequestBody SyncInformModel syncInformModel) {
        return paymentServer.sync(syncInformModel);
    }


}
