import { CACHE_API_KEY, CACHE_AUTH_USER, CACHE_ANONYMOUS_USER_ID } from "./constants";
import localStorage from './localStorage'

function getCacheApiKey() {
  const apiKey = localStorage.getItem(CACHE_API_KEY);
  return apiKey ? JSON.parse(apiKey) : null;
}

function getCacheAuthUser() {
  const user = localStorage.getItem(CACHE_AUTH_USER);
  return user ? JSON.parse(user) : null;
}

function getCacheAnonymousUser() {
  const user = localStorage.getItem(CACHE_ANONYMOUS_USER_ID);
  return user ? JSON.parse(user) : null;
}

function cacheUser(user: any) {
  localStorage.setItem(CACHE_AUTH_USER, JSON.stringify(user));
}

function deleteCacheUser() {
  localStorage.removeItem(CACHE_AUTH_USER);
}

export { cacheUser, deleteCacheUser, getCacheApiKey, getCacheAnonymousUser, getCacheAuthUser };
