package com.face.global.user;


import com.face.global.vo.GlobalOrgInfo;
import com.face.global.vo.GlobalUser;

public class UserStore {
    private static final ThreadLocal<GlobalUser> USER_THREAD_LOCAL_STORE = new InheritableThreadLocal<>();

    private static final ThreadLocal<String> USER_TOKEN = new InheritableThreadLocal<>();

    private static final ThreadLocal<GlobalOrgInfo> ORG_INFO = new InheritableThreadLocal<>();

    public static void setUser(GlobalUser globalUser) {
        USER_THREAD_LOCAL_STORE.set(globalUser);
    }
    public static void setUserToken(String token) {
        USER_TOKEN.set(token);
    }

    public static GlobalUser getCurrentUser() {
        return USER_THREAD_LOCAL_STORE.get();
    }
    public static String getUserToken() {
        return USER_TOKEN.get();
    }

    public static void setOrgInfo(GlobalOrgInfo orgInfo) {
        ORG_INFO.set(orgInfo);
    }

    public static GlobalOrgInfo getOrgInfo() {
        return ORG_INFO.get();
    }

    public static String getCurrentOrgId() {
        if (ORG_INFO.get() != null) {
            return ORG_INFO.get().getOrgId();
        }
        return null;
    }

    public static void clearUserInfo () {
        USER_THREAD_LOCAL_STORE.remove();
        USER_TOKEN.remove();
        ORG_INFO.remove();
    }

    public static String getCurrentUserId() {
        if (UserStore.getCurrentUser() != null) {
            return UserStore.getCurrentUser().getUserId();
        }
        return null;
    }

    public static String getToken() {
        return UserStore.getUserToken();
    }

    public static String getCurrentUserType() {
        if (UserStore.getCurrentUser() != null) {
            return UserStore.getCurrentUser().getUserType();
        }
        return null;
    }

}
