/**
 * Options passed to `IStoreProp`.
 */
export interface ILocalStorageOptions {
  default?: any;
}

export type StorageValueType =
  | 'string'
  | 'bool'
  | 'number'
  | 'date'
  | 'object'
  | 'null';

/**
 * A stored value.
 */
export interface ILocalStorageValue {
  type: StorageValueType;
  value: any;
}

/**
 * A platform independent persistent store.
 */
export interface ILocalStorage {
  getItem(key: string): Promise<any>;
  setItem(key: string, value: any): Promise<void>;
  removeItem(key: string): Promise<void>;
}

/**
 * An event that is fired when the local storage is accessed.
 */
export interface ILocalStorageChangedEvent {
  key: string;
  value: any;
  type: StorageValueType;
}

export type LocalStoragePropertyFunc<T> = (
  value?: T | null,
  options?: ILocalStorageOptions,
) => Promise<T | undefined>;

export type LocalStorageProp<T> = LocalStoragePropertyFunc<T> & {
  key: string;
  isProp: boolean;
};

export type LocalStoragePropertyFactory = <T>(
  key: string,
  defaultOptions?: ILocalStorageOptions,
) => LocalStorageProp<T>;
