import { Injectable } from '@angular/core';
import { StorageProvider } from './storage-provider';

@Injectable({ providedIn: 'root' })
export class SessionStorageProvider implements StorageProvider {
  set(key: string, value: unknown): void {
    sessionStorage.setItem(key, JSON.stringify(value));
  }
  get(key: string): unknown {
    const data = sessionStorage.getItem(key);
    if (data) {
      return JSON.parse(data);
    }
    return data;
  }

  clear(key: string): void {
    sessionStorage.removeItem(key);
  }
}
