import { LocalStorage } from '@assets/js-shop/LocalStorage';
import { IGraphQLGtmData } from '@assets/interfaces/gqlApi/graphql';
import { CACHE_KEY_DATA } from '@assets/js-shop/Shop';

export const CACHE_GTM_USER_OBJECT = 'js-shop-gtm-user';

export class GTMUserUtil {
   static init() {}

   static update(gtmData: IGraphQLGtmData) {
      const userObject = JSON.parse(gtmData.user);

      this.persist(userObject);
   }

   private static persist(userObject: any) {
      LocalStorage.set(
         CACHE_GTM_USER_OBJECT,
         userObject,
         LocalStorage.getItemTTL(CACHE_KEY_DATA) ?? 0,
      );
   }

   static clear() {
      LocalStorage.remove(CACHE_GTM_USER_OBJECT);
   }
}
