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

/*
 * 盛付通 普通商户配置
 *
 * @author jmdhappy
 *
 * @date 2021/12/13 16:00
 */
@Data
public class ShengpayNormalMchParams extends NormalMchParams {

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

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

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

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

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

    /** 退款挂起(如果挂起，退款余额不足时会挂起，有余额后会自动退款) **/
    private String isComplement;

    @Override
    public String deSenData() {

        ShengpayNormalMchParams 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));
        }
        return ((JSONObject) JSON.toJSON(isvParams)).toJSONString();
    }

}
