package com.sxyz.rfid.utils;

import android.text.TextUtils;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.StringUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.orhanobut.hawk.Hawk;
import com.sxyz.rfid.presenter.model.LoginModel;

import java.util.ArrayList;
import java.util.List;

public class LocalUtils {
    public final static String AUTO_USER_NAME = "name";
    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 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 void clearSp() {
        Hawk.deleteAll();
        SPUtils.getInstance().put(TOKEN, "");
    }

}
