package com.tofly.latte_core.utils;

import com.tofly.latte_core.config.ConfigKeys;
import com.tofly.latte_core.config.Latte;

import java.io.Serializable;

/**
 * @ClassName: AccountManager
 * @Description: 存储用户信息
 * @Author: Rivan
 * @CreateDate: 2020/9/1 0:17
 * @UpdateDate: 2020/9/1 0:17
 */
public class AccountManager implements Serializable {

    public static void setUserPermission(boolean isPermission) {
        LattePreference.setBoolean(SignTag.USER_PERMISSION.name(), SignTag.USER_PERMISSION.name(), isPermission);

    }

    public static boolean getUserPermission() {
        return LattePreference.getBoolean(SignTag.USER_PERMISSION.name(), SignTag.USER_PERMISSION.name(), false);
    }


    private enum SignTag {
        /**
         * 标记
         */
        SIGN_TAG,
        /**
         * 用户id
         */
        USER_ID,
        /**
         * 用户账号
         */
        USER_NAME,
        /**
         * 用户姓名
         */
        REAL_NAME,
        /**
         * 邮箱
         */
        USER_EMAIL,
        /**
         * 头像
         */
        USER_IMAGE,
        /**
         * 密码
         */
        USER_PASSWORD,
        /**
         * 权限
         */
        PERMISSION,
        /**
         * 部门
         */
        DEPARTMENT_NAME,
        /**
         * 部门id
         */
        DEPARTMENT_NAME_ID,
        /**
         * 电话
         */
        TLL_PHONE,
        /**
         * 签名
         */
        ESIGNATURE,
        /**
         * 用户
         */
        USER,
        /**
         * token
         */
        USER_TOKEN,
        /**
         * 用户权限
         */
        USER_PERMISSION,
        /**
         * 工作岗位
         */
        USER_JOB,
        /**
         * 工作职责
         */
        USER_NOte
    }

    //保存用户登录状态，登录后调用
    public static void setSignState(boolean state) {
        LattePreference.setAppFlag(SignTag.SIGN_TAG.name(), state);
    }


    public static void setPermission(String permission) {
        LattePreference.setString(SignTag.PERMISSION.name(), permission);
    }


    public static String getPermission() {
        return LattePreference.getString(SignTag.PERMISSION.name());
    }

    public static void setUserImage(String image) {
        LattePreference.setString(SignTag.USER_IMAGE.name(), image);
    }

    public static String getUserImage() {
        return LattePreference.getString(SignTag.USER_IMAGE.name());
    }

    public static void clearUserName() {
        LattePreference.clearStringByKey(SignTag.USER_NAME.name());
    }


    public static void setUsername(String name) {
        LattePreference.setString(SignTag.USER_NAME.name(), name);
    }

    public static String getUsername() {
        return LattePreference.getString(SignTag.USER_NAME.name());
    }

    public static void setUserPassword(String password) {
        LattePreference.setString(SignTag.USER_PASSWORD.name(), password);
    }

    public static String getUserPassword() {
        return LattePreference.getString(SignTag.USER_PASSWORD.name());
    }

    public static void clearAll() {
        LattePreference.clearAppPreferences();
    }

    //保存用户名id
    public static void setUserId(int id) {
        LattePreference.setAppFlag(SignTag.USER_ID.name(), id);
    }

    //取出用户名id
    public static int getUserId() {
        return LattePreference.getAppint(SignTag.USER_ID.name());
    }

    public static void setUserEmail(String email) {
        LattePreference.setString(SignTag.USER_EMAIL.name(), email);
    }

    public static void setJob(String job) {
        LattePreference.setString(SignTag.USER_JOB.name(), job);
    }

    public static String getJob() {
        return LattePreference.getString(SignTag.USER_JOB.name());
    }

    public static void setNote(String note) {
        LattePreference.setString(SignTag.USER_NOte.name(), note);
    }

    public static String getNote() {
        return LattePreference.getString(SignTag.USER_NOte.name());
    }

    public static void setUser(String user) {
        LattePreference.setString(SignTag.USER.name(), user);
    }

    public static String getUser() {
        return LattePreference.getString(SignTag.USER.name());
    }

    public static void setUserRealName(String realName) {
        LattePreference.setString(SignTag.REAL_NAME.name(), realName);
    }

    public static String getUserRealName() {
        return LattePreference.getString(SignTag.REAL_NAME.name());
    }

    public static void setDepartment(String user) {
        LattePreference.setString(SignTag.DEPARTMENT_NAME.name(), user);
    }

    public static String getDepartment() {
        return LattePreference.getString(SignTag.DEPARTMENT_NAME.name());
    }

    public static void setDepartmentId(int departmentId) {
        LattePreference.setInt(SignTag.DEPARTMENT_NAME_ID.name(), departmentId);
    }

    public static int getDepartmentId() {
        return LattePreference.getInt(SignTag.DEPARTMENT_NAME_ID.name());
    }

    public static void setEsignature(String esignature) {
        LattePreference.setString(SignTag.ESIGNATURE.name(), esignature);
    }

    public static String getEsignature() {
        return LattePreference.getString(SignTag.ESIGNATURE.name());
    }

    public static void setTllPhone(String user) {
        LattePreference.setString(SignTag.TLL_PHONE.name(), user);
    }

    public static String getTllPhone() {
        return LattePreference.getString(SignTag.TLL_PHONE.name());
    }

    public static String getUserEmail() {
        return LattePreference.getString(SignTag.USER_EMAIL.name());
    }

    public static String getPictureUrl() {
        return Latte.getConfiguration(ConfigKeys.API_HOST.name()) + "/base/file/loadImg?access_token=" + LattePreference.getString("token") + "&remotePath=";
    }

    public static boolean isSignIn() {
        return LattePreference.getAppFlag(SignTag.SIGN_TAG.name());
    }


    public static void checkAccount(IUserChecker checker) {
        if (isSignIn()) {
            checker.onSignIn();
        } else {
            checker.onNotSignIn();
        }
    }
}
