export type V3ErrorCode =
  | 'V3_UNAVAILABLE'
  | 'V3_DEGRADED'
  | 'V3_WRITES_BLOCKED';

export class V3Error extends Error {
  public readonly details: Readonly<Record<string, unknown>>;
  public readonly cause?: unknown;

  constructor(
    public readonly code: V3ErrorCode,
    message: string,
    details: Readonly<Record<string, unknown>> = {},
    cause?: unknown,
  ) {
    super(message);
    this.name = new.target.name;
    this.details = cloneAndDeepFreeze(details);
    this.cause = cause;
  }
}

export class V3UnavailableError extends V3Error {
  constructor(message: string, details: Readonly<Record<string, unknown>> = {}, cause?: unknown) {
    super('V3_UNAVAILABLE', message, details, cause);
  }
}

export class V3DegradedError extends V3Error {
  constructor(message: string, details: Readonly<Record<string, unknown>> = {}, cause?: unknown) {
    super('V3_DEGRADED', message, details, cause);
  }
}

export class V3WritesBlockedError extends V3Error {
  constructor(message: string, details: Readonly<Record<string, unknown>> = {}, cause?: unknown) {
    super('V3_WRITES_BLOCKED', message, details, cause);
  }
}
import { cloneAndDeepFreeze } from './freeze';
