package com.xingxi.unifiedpay.domain;

import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

@Data
public class MercUnifiedpayDTO {

    private Long mercId;
    private String subMchid;
    private String paymentMethod;
    private String paymentChannel;

    private Long callUnifiedpayMercId;
    private String unifiedPayMethod;
    private String callUnifiedPayMercRole;

    public Long getCallUnifiedpayMercId() {
        if (ObjectUtils.isEmpty(callUnifiedpayMercId)) {
            switchMercUnifiepay();
        }

        return callUnifiedpayMercId;
    }

    public String getUnifiedPayMethod() {
        if (StringUtils.isEmpty(unifiedPayMethod)) {
            switchMercUnifiepay();
        }

        return unifiedPayMethod;
    }

    public String getCallUnifiedPayMercRole() {
        if (StringUtils.isEmpty(callUnifiedPayMercRole)) {
            switchMercUnifiepay();
        }

        return callUnifiedPayMercRole;
    }


    private void setCallUnifiedpayMercId(Long callUnifiedpayMercId) {
        this.callUnifiedpayMercId = callUnifiedpayMercId;
    }

    private void setUnifiedPayMethod(String unifiedPayMethod) {
        this.unifiedPayMethod = unifiedPayMethod;
    }

    private void setCallUnifiedPayMercRole(String callUnifiedPayMercRole) {
        this.callUnifiedPayMercRole = callUnifiedPayMercRole;
    }

    /**
     * 商户收款+微信支付    商户自己上传证书 自己微信支付收款
     * 商户收款+电商收付通  我们的电商收付通
     * 平台收款+微信支付    我们的微信支付
     * <p>
     * payment_method
     * PLATFORM_PAYMENT 平台收款
     * MERCHANT_PAYMENT 商户收款
     * payment_channel
     * PAYTYPE_WX_PAY 微信支付
     * PAYTYPE_WX_ECOMMERCE 微信收付通
     *
     * @return payType
     */
    private MercUnifiedpayDTO switchMercUnifiepay() {
        String payType = getPaymentMethod() + getPaymentChannel();
        switch (payType) {
            case "MERCHANT_PAYMENTPAYTYPE_WX_PAY": // 微信支付 商户自己上传证书
                setCallUnifiedpayMercId(getMercId());
                setUnifiedPayMethod("WXPay");
                setCallUnifiedPayMercRole("merchant");
                break;
            case "MERCHANT_PAYMENTPAYTYPE_WX_ECOMMERCE": // 电商收付通合单支付
                setCallUnifiedpayMercId(getMercId());
                setUnifiedPayMethod("EcommerceWXPay");
                setCallUnifiedPayMercRole("merchant");
                break;
            case "PLATFORM_PAYMENTPAYTYPE_WX_PAY": //微信支付平台支付证书
                setCallUnifiedpayMercId(100L);
                setUnifiedPayMethod("WXPay");
                setCallUnifiedPayMercRole("platform");
                break;
            default:
                setCallUnifiedpayMercId(99999999999L);
                setUnifiedPayMethod("OtherPayTest");
                setCallUnifiedPayMercRole("UNKNOW");
                break;
        }
        return this;
    }

}
