import { Injectable } from '@angular/core';
import {KeyringAPI} from '@chatenium/chatenium-sdk/storage/keyring';
import {KeyValueAPI} from '@chatenium/chatenium-sdk/storage/keyvalue';

@Injectable({
  providedIn: 'root',
})
export class KeyValue {
  getApi(): KeyValueAPI {
    return {
      set: (key, value) => {
        localStorage.setItem(key, value)
      },
      get: key => {
        return new Promise(r => r(localStorage.getItem(key) ?? ""))
      },
      delete: key => {
        return localStorage.removeItem(key)
      },
      flush: () => {
        return localStorage.clear()
      }
    }
  }
}
