package com.jeequan.jeepay.core.model.params.joinpay;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.annotate.ChannelMchId;
import com.jeequan.jeepay.core.constants.ChannelMchIdTypeEnum;
import com.jeequan.jeepay.core.model.params.NormalMchParams;
import com.jeequan.jeepay.core.utils.StringKit;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 汇聚支付 配置信息
 *
 * @author yurong
 *
 * @date 2022/7/18 9:49
 */
@Data
public class JoinpayNormalMchParams extends NormalMchParams {

    /**
     * 商户号
     **/
    @ChannelMchId(type = ChannelMchIdTypeEnum.MCH_NO)
    private String merchantNo;

    /**
     * 报备商户号
     **/
    private String tradeMerchantNo;

    /**
     * 终端设备号 被扫必填 商家扫客户
     **/
    private String terminalNo;

    /**
     * 加密类型 MD5 1 和 RSA 2
     **/
    private String encryptType;

    /**
     * 秘钥 MD5加签
     **/
    private String merchantKey;

    /**
     * 商户私钥 RSA加签
     **/
    private String privateKey;

    /**
     * 汇聚平台公钥 RSA解签
     **/
    private String publicKey;


    @Override
    public String deSenData() {

        JoinpayNormalMchParams joinParams = this;
        if (StringUtils.isNotBlank(this.merchantKey)) {
            joinParams.setMerchantKey(StringKit.str2Star(this.merchantKey, 0, 3, 6));
        }
        if (StringUtils.isNotBlank(this.publicKey)) {
            joinParams.setPublicKey(StringKit.str2Star(this.publicKey, 0, 3, 6));
        }
        if (StringUtils.isNotBlank(this.privateKey)) {
            joinParams.setPrivateKey(StringKit.str2Star(this.privateKey, 0, 3, 6));
        }
        return ((JSONObject) JSON.toJSON(joinParams)).toJSONString();
    }

}
