package com.ruansee.macall.testwebview.app;

import com.rs.macall.androidx.basemodel.utils.StringUtil;

/**
 * created by:   Macall
 * create time:  2023/12/7 9:20
 * copyright:    @ruansee.com
 * Describe:
 */
public class AppCacheData {
    private static AppCacheData cacheData;

    private String userCode;
    private String userName;
    private String idCardNum;
    private String deptCode;
    private String deptName;

    private String appUrl;

    private String appName;

    private String clientId;
    private String clientSecret;


    private AppCacheData(){

    }

    /**
     * 用户信息是否有效
     * @return
     */
    public boolean isUserEffective(){
        if (StringUtil.isContainEmpty(getUserCode(),getIdCardNum(),getDeptCode(),getClientId(),getClientSecret()))return false;
        return true;
    }

    public static AppCacheData getCacheData() {
        if (cacheData ==null){
            synchronized (AppCacheData.class){
                if (cacheData == null){
                    cacheData = new AppCacheData();
                }
            }
        }
        return cacheData;
    }

    public String getUserCode() {
        if (StringUtil.isNullOrEmpty(userCode)){
            userCode = RuanseeApp.getStringValue("userCode");
        }
        return userCode;
    }

    public void setUserCode(String userCode) {
        RuanseeApp.saveData("userCode",userCode);
        this.userCode = userCode;
    }

    public String getUserName() {
        if (StringUtil.isNullOrEmpty(userName)){
            userName = RuanseeApp.getStringValue("userName");
        }
        return userName;
    }

    public void setUserName(String userName) {
        RuanseeApp.saveData("userName",userName);
        this.userName = userName;
    }

    public String getIdCardNum() {
        if (StringUtil.isNullOrEmpty(idCardNum)){
            idCardNum = RuanseeApp.getStringValue("idCardNum");
        }
        return idCardNum;
    }

    public void setIdCardNum(String idCardNum) {
        RuanseeApp.saveData("idCardNum",idCardNum);
        this.idCardNum = idCardNum;
    }

    public String getDeptCode() {
        if (StringUtil.isNullOrEmpty(deptCode)){
            deptCode = RuanseeApp.getStringValue("deptCode");
        }
        return deptCode;
    }

    public void setDeptCode(String deptCode) {
        RuanseeApp.saveData("deptCode",deptCode);
        this.deptCode = deptCode;
    }

    public String getDeptName() {
        if (StringUtil.isNullOrEmpty(deptName)){
            deptName = RuanseeApp.getStringValue("deptName");
        }
        return deptName;
    }

    public void setDeptName(String deptName) {
        RuanseeApp.saveData("deptName",deptName);
        this.deptName = deptName;
    }

    public String getAppUrl() {
        if (StringUtil.isNullOrEmpty(appUrl)){
            appUrl = RuanseeApp.getStringValue("appUrl");
        }
        return appUrl;
    }

    public void setAppUrl(String appUrl) {
        this.appUrl = appUrl;
        RuanseeApp.saveData("appUrl",appUrl);
    }

    public String getAppName() {
        if (StringUtil.isNullOrEmpty(appName)){
            appName = RuanseeApp.getStringValue("appName");
        }
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
        RuanseeApp.saveData("appName",appName);
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
        RuanseeApp.saveData("clientId",clientId);
    }

    public String getClientSecret() {
        if (StringUtil.isNullOrEmpty(clientSecret)){
            clientSecret = RuanseeApp.getStringValue("clientSecret");
        }
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
        RuanseeApp.saveData("clientSecret",clientSecret);
    }

    public String getClientId() {
        if (StringUtil.isNullOrEmpty(clientId)){
            clientId = RuanseeApp.getStringValue("clientId");
        }
        return clientId;
    }
}
