package com.sxyz.rfid.utils;

import android.text.TextUtils;

import com.blankj.utilcode.util.SPUtils;
import com.orhanobut.hawk.Hawk;
import com.sxyz.rfid.App;
import com.sxyz.rfid.presenter.model.LoginModel;

public class LocalUtils {
    public final static String AUTO_USER_NAME = "name";
    public final static String USER_NAME = "userName";
    public final static String NICK_NAME = "nickName";
    public final static String USER_ID = "userId";
    public final static String AUTO_PWD = "pwd";
    public final static String TOKEN = "token";
    public final static String LOGIN_MODEL = "loginModel";

    public final static String AI = "1";//分析
    public final static String CASE = "2";//案例
    public final static String POINT = "3";//观点
    public final static String LAW = "4";//法规

    /**
     * @description 是否登录？
     * @author wuchunyuan
     * @time 2020/7/22 13:16
     */
    public static boolean isLogin() {
        String name = SPUtils.getInstance().getString(AUTO_USER_NAME);
        String pwd = SPUtils.getInstance().getString(AUTO_PWD);
        if (TextUtils.isEmpty(name) && TextUtils.isEmpty(pwd)) {
            return false;
        } else {
            return true;
        }
    }

    public static String getUserName() {
        String userName = SPUtils.getInstance().getString(AUTO_USER_NAME);
        return userName == null ? "" : userName;
    }

    public static String getUserName1() {
        String userName = SPUtils.getInstance().getString(USER_NAME);
        return userName == null ? "" : userName;
    }

    public static String getNickName() {
        String nickName = SPUtils.getInstance().getString(NICK_NAME);
        return nickName == null ? "" : nickName;
    }

    /**
     * @description 获取用户ID
     * @author wuchunyuan
     * @time 2020/7/22 13:16
     */
    public static int getUserId() {
        int userId = SPUtils.getInstance().getInt(USER_ID);
        return userId == 0 ? -1 : userId;
    }

    public static String getToken() {
        String accessToken = SPUtils.getInstance().getString(TOKEN);
        return accessToken == null ? "" : accessToken;
    }

    public static String getPassWord() {
        String password = SPUtils.getInstance().getString(AUTO_PWD);
        return password == null ? "" : password;
    }

    public static LoginModel getLoginModel() {
        LoginModel loginModel = Hawk.get(LOGIN_MODEL);
        return loginModel;
    }

//    public static String getUrl(String path) {
//        String ipPort = TextUtils.isEmpty(App.ip) ? AppConfig.BASE_URL : getIpPort();
//        return ipPort + path;
//    }

    public static String getIpPort() {
        return "http://" + App.ip + ":" + App.port + "/";
    }

    public static void clearSp() {
        Hawk.deleteAll();
        SPUtils.getInstance().put(TOKEN, "");
        SPUtils.getInstance().put(AUTO_USER_NAME, "");
        SPUtils.getInstance().put(AUTO_PWD, "");
        SPUtils.getInstance().put(USER_ID, "");
        SPUtils.getInstance().put(NICK_NAME, "");
        SPUtils.getInstance().put(USER_NAME, "");
    }

}
