// Response card type identifiers
export type ResponseCardType = 
  | 'idle'           // No request sent yet
  | 'loading'        // Request in progress
  | 'success'        // 2xx response
  | 'error'          // 4xx/5xx response or network error
  | 'streaming'      // SSE/streaming response

// Response metadata
export interface ResponseMeta {
  status: number
  statusText: string
  responseTime: number
  size: number
  isStreaming?: boolean
}

// Base interface for response card props
export interface BaseResponseCardProps {
  type: ResponseCardType
}

// Idle state - no request sent
export interface IdleCardProps extends BaseResponseCardProps {
  type: 'idle'
}

// Loading state
export interface LoadingCardProps extends BaseResponseCardProps {
  type: 'loading'
}

// Success response (2xx)
export interface SuccessCardProps extends BaseResponseCardProps {
  type: 'success'
  meta: ResponseMeta
  body: string
  headers: Record<string, string>
  contentType: string | null
}

// Error response (4xx/5xx or network error)
export interface ErrorCardProps extends BaseResponseCardProps {
  type: 'error'
  meta?: ResponseMeta
  body?: string
  headers?: Record<string, string>
  contentType?: string | null
  errorMessage?: string
  // Debug callback
  onDebug?: () => void
}

// Streaming response
export interface StreamingCardProps extends BaseResponseCardProps {
  type: 'streaming'
  meta: ResponseMeta
  body: string
  headers: Record<string, string>
  contentType: string | null
}

// Union type for all response card props
export type ResponseCardProps = 
  | IdleCardProps 
  | LoadingCardProps 
  | SuccessCardProps 
  | ErrorCardProps 
  | StreamingCardProps

// Helper to determine card type from status
export function getResponseCardType(
  status: number | null, 
  isStreaming: boolean = false,
  hasError: boolean = false
): ResponseCardType {
  if (isStreaming) return 'streaming'
  if (hasError && status === null) return 'error'
  if (status === null) return 'idle'
  if (status >= 200 && status < 300) return 'success'
  return 'error'
}
