/**
 * AI error types — system-ai.
 * AIProviderError carries a code and retryable flag to drive the fallback chain.
 */

export class AIProviderError extends Error {
  constructor(
    public code: 'rate_limit' | 'timeout' | 'model_unavailable' | 'auth_error' | 'unknown',
    public provider: string,
    public retryable: boolean,
    message: string,
  ) {
    super(message)
    this.name = 'AIProviderError'
  }
}

/**
 * Re-exported from @zync/db usage helper for credit blocks.
 * Keeping the re-export here so callers of @zync/ai don't need to import from @zync/db.
 */
export { QuotaExceededError } from '@zync/db/queries'

/**
 * Thrown when a tenant's extra usage spend limit is exceeded.
 * Maps to HTTP 402.
 */
export class ExtraSpendLimitError extends Error {
  constructor(message = 'Extra spend limit exceeded') {
    super(message)
    this.name = 'ExtraSpendLimitError'
  }
}
