import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage-angular';

@Injectable({
  providedIn: 'root'
})
export class StorageService {

  private _storage: Storage | null = null;

  constructor(private storage: Storage) {}

  async init() {
    console.log("[StorageService] Initializing storage...");
    const storage = await this.storage.create();
    this._storage = storage;
  }

  public async set(key: string, value: any) {
    console.log("[StorageService] Setting value in storage:", key, value);
    await this._storage?.set(key, value);
  }
  
  public async get(key: string) {
    console.log("[StorageService] Getting value from storage:", key);
    return await this._storage?.get(key);
  }
  public async remove(key: string){
    console.log("[StorageService] removing value from storage:", key);
    return await this._storage?.remove(key);
  }

}