package com.jeequan.jeepay.core.model.device;

import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.utils.StringKit;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/***
* 厂商设备参数   易联云
*
* @author zx
* 
* @date 2021/12/30 9:01
*/
@Data
public class YlyParams extends DeviceParams {

    public ProviderParams providerParams;

    public DeviceParams deviceParams;

    public BizConfigParams bizConfigParams;

    public YlyParams(ProviderParams providerParams) {
        this.providerParams = providerParams;
    }

    public YlyParams(ProviderParams providerParams, DeviceParams deviceParams, BizConfigParams bizConfigParams) {
        this.providerParams = providerParams;
        this.deviceParams = deviceParams;
        this.bizConfigParams = bizConfigParams;
    }

    @Data
    public static class ProviderParams {
        /**
         * clientId
         */
        private String clientId;

        /**
         * clientSecret
         */
        private String clientSecret;

        /**
         * accessToken
         */
        private String accessToken;

        /**
         * keywords K8设备关键词
         */
        private String keywords;

        /**
         * printSetIcon 打印LOGO配置
         */
        private String printSetIcon;

        /**
         * pushMsgKey 推送应用公钥
         */
        private String pushPublicKey;

        /**
         * pushMsgKey 易联云公钥
         */
        private String platPublicKey;

    }

    @Data
    public static class DeviceParams {

        /**
         * 设备号
         */
        private String deviceNo;
        /**
         * 终端秘钥
         */
        private String deviceKey;

    }

    @Data
    public static class BizConfigParams {

        /**
         * 打印联数
         */
        private Integer printNum;

        /**
         * 打印机模式
         */
        private Byte printMode;

    }

    @Override
    public String deSenData() {
        ProviderParams params = this.getProviderParams();
        if (params != null && StringUtils.isNotBlank(params.getClientSecret())) {
            params.setClientSecret(StringKit.autoDesensitization(params.getClientSecret()));
        }
        if (params != null && StringUtils.isNotBlank(params.getAccessToken())) {
            params.setAccessToken(StringKit.autoDesensitization(params.getAccessToken()));
        }
        if (params != null && StringUtils.isNotBlank(params.getPushPublicKey())) {
            params.setPushPublicKey(StringKit.autoDesensitization(params.getPushPublicKey()));
        }
        if (params != null && StringUtils.isNotBlank(params.getPlatPublicKey())) {
            params.setPlatPublicKey(StringKit.autoDesensitization(params.getPlatPublicKey()));
        }

        return JSONObject.toJSONString(params);
    }

}
