package com.czg.pay;

import lombok.Data;
import lombok.NonNull;

/**
 * @author ww
 */
@Data
public class CzgPayBaseReq {
    //必填范围
    /**
     * 订单标题
     */
    private String subject;

    /**
     * 订单描述 String(256)
     */
    private String body;
    /**
     * 交易金额 分
     */
    private Long amount;
    /**
     * 货币类型 cny
     */
    private String currency = "cny";
    /**
     * 商户订单号 String(30)
     * 操作方式+雪花算法
     * 收银机客户端  PC+雪花ID
     * 微信小程序 WX+雪花ID
     * 支付宝小程序 ALI+雪花ID
     * PC管理端 WEB+雪花ID
     * APP管理端 APP+雪花ID
     * <p>
     * 退款 re+雪花ID
     */
    private String mchOrderNo;

    /**
     * 异步通知地址 String(128)
     * 支付结果异步回调URL,只有传了该值才会发起回调
     */
    private String notifyUrl;
    /**
     * 扩展参数 String(512)
     * 商户扩展参数,回调时会原样返回
     * * 扩展参数
     * * {
     * *     "pay_type": "order/vip"
     * * }
     */
    private String extParam;


    /**
     * 原生支付 不需要 store_id
     */
    private String storeId;


    /**
     * 支付类型
     * {@link com.czg.constants.SystemConstants.PayType}
     */
    private String payType;
    /**
     * 用户唯一标识 String(30)
     * 微信支付时，传入用户的openId；
     * 支付宝支付和银联支付时，传入用户的userId
     */
    private String userId;
    /**
     * 用户IP
     * 需要传付款用户客户端IP地址
     */
    private String clientIp;
    /**
     * 子商户 appid ，微信付款支付的时候 需要上送
     * isScreen 为 false 的情况下需要传入
     */
    private String subAppid;

    /**
     * 支付条码
     */
    private String authCode;

    public CzgPayBaseReq() {

    }

    public CzgPayBaseReq(String mchOrderNo, String detail, Long amount, String payType, String userId, String clientIp) {
        this.mchOrderNo = mchOrderNo;
        this.subject = detail;
        this.body = detail;
        this.amount = amount;
        this.payType = payType;
        this.userId = userId;
        this.clientIp = clientIp;
    }

    public void polyBase(@NonNull String storeId, @NonNull String notifyUrl) {
        this.storeId = storeId;
        this.notifyUrl = notifyUrl;
    }

    public static CzgPayBaseReq ltPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
            , @NonNull String payType, @NonNull String openId, @NonNull String clientIp) {
        return new CzgPayBaseReq(mchOrderNo, detail, amount, payType, openId, clientIp);
    }

    public static CzgPayBaseReq h5PayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
        return new CzgPayBaseReq(mchOrderNo, detail, amount, null, null, clientIp);
    }

    public static CzgPayBaseReq jsPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
            , @NonNull String payType, @NonNull String openId, @NonNull String clientIp) {
        return new CzgPayBaseReq(mchOrderNo, detail, amount, payType, openId, clientIp);
    }

    public static CzgPayBaseReq scanPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
        return new CzgPayBaseReq(mchOrderNo, detail, amount, null, null, clientIp);
    }

    public static CzgPayBaseReq microPay(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String authCode) {
        CzgPayBaseReq stringReq = new CzgPayBaseReq(mchOrderNo, detail, amount, null, null, null);
        stringReq.setAuthCode(authCode);
        return stringReq;
    }
}
