import request from '@/utils/http'

export interface OutboxEvent {
  event_id: string
  event_type: string
  event_version: number
  tenant_id: string | null
  aggregate_type: string
  aggregate_id: string
  payload: Record<string, unknown>
  trace_context: Record<string, unknown>
  occurred_at: string
  available_at: string
  attempts: number
  locked_at: string | null
  locked_by: string | null
  processed_at: string | null
  dead_lettered_at: string | null
  last_error: string | null
  published_stream_id: string | null
}

export function fetchOutboxEvents(params: { status?: string; type?: string; limit?: number }) {
  return request.get<OutboxEvent[]>({ url: '/api/v1/admin/outbox-events', params })
}

export function retryOutboxEvent(eventId: string) {
  return request.post<{ retried: boolean }>({ url: `/api/v1/admin/outbox-events/${eventId}/retry` })
}
