/**
 * Shared error classes for consistent error handling
 * @countermeasure/web-components/utils/errors
 */

/** Base error class for all component library errors */
export class ComponentError extends Error {
  constructor(message: string) {
    super(message)
    this.name = 'ComponentError'
  }
}

/** Error thrown when configuration is invalid */
export class ConfigError extends ComponentError {
  constructor(component: string, message: string) {
    super(`[${component}] ${message}`)
    this.name = 'ConfigError'
  }
}

/** Error thrown during input validation */
export class ValidationError extends ComponentError {
  public readonly field: string

  constructor(field: string, message: string) {
    super(`Validation failed for "${field}": ${message}`)
    this.name = 'ValidationError'
    this.field = field
  }
}

/** Error thrown during network operations */
export class NetworkError extends ComponentError {
  public readonly status: number
  public readonly statusText: string

  constructor(status: number, statusText: string, message?: string) {
    super(message ?? `HTTP ${String(status)}: ${statusText}`)
    this.name = 'NetworkError'
    this.status = status
    this.statusText = statusText
  }
}
