// API request/response type definitions

export interface ApiError {
  code: string;
  message: string;
  data?: {
    status?: number;
    errors?: Array<{
      code: string;
      message: string;
      context?: Record<string, unknown>;
    }>;
    [key: string]: unknown;
  };
}

/**
 * Custom error class that preserves the full API error response
 * This allows callers to access validation errors and other details
 */
export class ApiRequestError extends Error {
  code: string;
  data?: ApiError['data'];
  status: number;

  constructor(message: string, code: string, status: number, data?: ApiError['data']) {
    super(message);
    this.name = 'ApiRequestError';
    this.code = code;
    this.status = status;
    this.data = data;
  }
}
