package com.ycgis.macall.personalcenter.p.app;

import com.anhui.police.auth.sdk.AuthType;
import com.rs.macall.androidx.basemodel.utils.StringUtil;
import com.ycgis.macall.personalcenter.util.IPAddressUtils;

/**
 * created by:   Macall
 * create time:  2023/10/27 15:07
 * copyright:    @ruansee.com
 * Describe:
 */
public class AppCache {

    private static AppCache appCache;
    private  String BASE_URL = "";
    //http://192.168.0.233/dev-api/profile/upload/2023/01/02/icon_banner1.png
    public static final String BASE_IMAGE_URL = "http://20.90.2.2/pcenter_img_out";
//    public static final String BASE_IMAGE_URL = "http://192.168.43.98:3000/prod-api/";

    private AuthType authType;
    private String appToke;

    private String ip;
    private String port;

    private String localIp;

    //系统Token
    private String system_token;

    //服务总线token
    private String access_token;
    //应用申请token
    private String apply_token;

    //统一认证token
    private String token;

    /* 用户信息加密 */
    private String userInfo;

    private String imei,imsi;

    private AppCache() {

    }

    public synchronized static AppCache getAppCacheData() {
        if (appCache == null){
            synchronized (AppCache.class){
                if (appCache == null) appCache = new AppCache();
            }
        }
        return appCache;
    }

    public void setIpAndPort(String ip,String port){
        this.ip = ip;
        this.port = port;
    }

    public String getBaseUrlPath() {
        if (StringUtil.isNullOrEmpty(BASE_URL)){
            BASE_URL = String.format("http://%s:%s/pcenter_app_out/",ip,port);
//            BASE_URL = String.format("http://%s:%s/wzt/",ip,port);
        }
        return BASE_URL;
    }

    public String getLocalIp() {
        if (StringUtil.isNullOrEmpty(localIp)){
            localIp = IPAddressUtils.getLocalIpAddress();
        }
        return localIp;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getSystem_token() {
        return system_token;
    }

    public void setSystem_token(String system_token) {
        this.system_token = system_token;
    }

    public String getAccess_token() {
        return access_token;
    }

    public void setAccess_token(String access_token) {
        this.access_token = access_token;
    }

    public String getApply_token() {
        return apply_token;
    }

    public void setApply_token(String apply_token) {
        this.apply_token = apply_token;
    }

    public String getToken() {
        return StringUtil.get(token,"");
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getUserInfo() {
        return StringUtil.get(userInfo,RuanseeApplication.getStringValue("appUserInfo"));
    }

    public void setUserInfo(String userInfo) {
        this.userInfo = userInfo;
        RuanseeApplication.saveData("appUserInfo",userInfo);
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public String getImsi() {
        return imsi;
    }

    public void setImsi(String imsi) {
        this.imsi = imsi;
    }

    public String getSysmCode() {
        return "11e8f9a0948a43d78f68c6af41c12242";
    }

    public void setAuthType(AuthType authType) {
        if (authType == AuthType.PWD){
            RuanseeApplication.saveData("authType",0);
        } else if (authType == AuthType.DIGITAL_CERTIFICATE) {
            RuanseeApplication.saveData("authType",1);
        }else if (authType == AuthType.GESTURE){
            RuanseeApplication.saveData("authType",2);
        }else if (authType == AuthType.FACE){
            RuanseeApplication.saveData("authType",3);
        }else if (authType == AuthType.VOICE){
            RuanseeApplication.saveData("authType",4);
        }else {
            RuanseeApplication.saveData("authType",0);
        }
        this.authType = authType;
        RuanseeApplication.saveData("isUpdateAuthType",true);
    }
    /**
     *  0 : 密码    1 数字证书   2：手势   3 ： 人脸   4 ：语音
     * @param authType          认证方式
     */
    public void setAuthType(int authType) {
        RuanseeApplication.saveData("authType",authType);
        switch (authType) {
            case 0:
                this.authType = AuthType.PWD;
                break;
            case 1:
                this.authType = AuthType.DIGITAL_CERTIFICATE;
                break;
            case 2:
                this.authType = AuthType.GESTURE;
                break;
            case 3:
                this.authType = AuthType.FACE;
                break;
            case 4:
                this.authType = AuthType.VOICE;
                break;
            default:
                this.authType = AuthType.PWD;
                break;
        }
    }

    public AuthType getAuthType() {
        if (authType == null) {
            int i = RuanseeApplication.getIntegerValue("authType");
            switch (i) {
                case 1:
                    authType = AuthType.DIGITAL_CERTIFICATE;
                    break;
                case 2:
                    authType = AuthType.GESTURE;
                    break;
                case 3:
                    authType = AuthType.FACE;
                    break;
                case 4:
                    authType = AuthType.VOICE;
                    break;
                default:
                    authType = AuthType.PWD;
                    break;
            }
        }
        return authType;
    }
}
