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

@Injectable({ providedIn: 'root' })
export class LocalStorageProvider implements StorageProvider {
  set(key: string, value: unknown): void {
    localStorage.setItem(key, JSON.stringify(value));
  }

  get(key: string): unknown {
    const data = localStorage.getItem(key);
    if (data) {
      return JSON.parse(data);
    }
    return data;
  }

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