import {
  StorageMock,
  SecureStorageMock,
  toObject,
  DEFAULT_NAMESPACE,
} from "./storageMock";

class IOSLocalStorage extends SecureStorageMock implements NativeLocalStorageI {
  async getAllItems(namespace = DEFAULT_NAMESPACE) {
    if (!this.items.has(namespace || DEFAULT_NAMESPACE)) {
      throw new Error("namespace not found");
    }

    return Promise.resolve(
      toObject(this.items.get(namespace || DEFAULT_NAMESPACE))
    );
  }
}

class IOSSessionStorage extends StorageMock implements NativeSessionStorageI {
  async getAllItems(namespace = DEFAULT_NAMESPACE) {
    if (!this.items.has(namespace || DEFAULT_NAMESPACE)) {
      throw new Error("namespace not found");
    }

    return Promise.resolve(
      toObject(this.items.get(namespace || DEFAULT_NAMESPACE))
    );
  }
}

export const localStorage = new IOSLocalStorage();

export const sessionStorage = new IOSSessionStorage();
