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

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.IsvParams;
import com.jeequan.jeepay.core.utils.StringKit;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/*
 * 盛付通 配置信息
 *
 * @author pangxiaoyu
 *
 * @date 2021/6/8 18:02
 */
@Data
public class ShengpayIsvParams extends IsvParams {

    /** 是否沙箱环境 */
    private Byte sandbox;

    /** mchId **/
    @ChannelMchId(type = ChannelMchIdTypeEnum.ISV_NO)
    private String mchId;

    /** privateKey 私钥 **/
    private String privateKey;

    /** 应用公钥（分账使用）**/
    private String appPublicKey;

    /** publicKey 盛付通公钥 **/
    private String publicKey;

    /** 小程序appId **/
    private String wxLiteAppId;

    @Override
    public String deSenData() {

        ShengpayIsvParams isvParams = this;
        if (StringUtils.isNotBlank(this.privateKey)) {
            isvParams.setPrivateKey(StringKit.str2Star(this.privateKey, 0, 3, 6));
        }
        if (StringUtils.isNotBlank(this.publicKey)) {
            isvParams.setPublicKey(StringKit.str2Star(this.publicKey, 6, 6, 6));
        }
        if (StringUtils.isNotBlank(this.appPublicKey)) {
            isvParams.setAppPublicKey(StringKit.str2Star(this.appPublicKey, 6, 6, 6));
        }
        return ((JSONObject) JSON.toJSON(isvParams)).toJSONString();
    }

}
