import { Jsonable } from '.'

export enum MetaStorageErrorType {
  'ENCRYPTION_KEY_REQUIRED' = 'Encryption key is required.',
  'HASHING_FAILED' = "Can't get encrypted file hash.",
  'FETCH_FAILED' = 'Fetching meta.json requires an encryption key.',
  'HASH_VERIFICATION_FAILED' = 'Unable to verify meta.json.',
  'DECRYPTION_FAILED' = 'Error decryping meta.json.',
  'UNHANDLED_FETCH_ERROR' = 'Unable to fetch meta.json. Something went wrong.',
  'NO_URLS_PROCESSED_SUCCESSFULLY' = 'No URLs were available to process.'
}

export class MetaStorageError extends Error {
  public readonly context?: Jsonable

  constructor(
    message: MetaStorageErrorType,
    options: { cause?: Error; context?: Jsonable } = {}
  ) {
    const { cause, context } = options

    super(message, { cause })
    this.name = this.constructor.name

    this.context = context
  }
}
