import { NAMESPACE } from "../constants/config/storage.config";
import store from "store";
import { SysUserInfo } from "../model/SysUserInfo";

/**
 * @description: 用户信息存储服务
 * @author ChenRui
 * @date 2020/8/27 10:46
 */
class UserStore {
  private static readonly USER = NAMESPACE + "user";
  private refreshMark = new Date().getTime();

  public set user(sysUserInfo: SysUserInfo | undefined) {
    this.refreshMark = new Date().getTime();
    if (sysUserInfo) {
      store.set(UserStore.USER, sysUserInfo);
    } else {
      store.remove(UserStore.USER);
    }
  }

  public get user(): SysUserInfo | undefined {
    if (this.refreshMark) {
      return store.get(UserStore.USER);
    }
  }
}
const userStore = new UserStore();
export { UserStore, userStore };
