export type KbxIntegrationState = 'queued' | 'delivering' | 'retrying' | 'delivered' | 'failed' | 'suspended'
export type KbxIntegrationDirection = 'inbound' | 'outbound'
export type KbxIntegrationTransport = 'outbox-http' | 'outbox-event' | 'inbox-event'
export type KbxIntegrationDelivery = 'at-most-once' | 'at-least-once'
export type KbxIntegrationCriticality = 'low' | 'medium' | 'high'

export interface KbxIntegrationShortRetryDefinition {
  maxRetryAttempts: number
  baseDelayMs: number
  backoff: 'constant' | 'exponential'
}

export interface KbxIntegrationLongRetryDefinition {
  scheduler: 'hangfire'
  maxAttempts: number
  scheduleSeconds: readonly number[]
}

export interface KbxIntegrationCircuitBreakerDefinition {
  failureRatio: number
  samplingSeconds: number
  minimumThroughput: number
  breakSeconds: number
}

export interface KbxIntegrationDefinition {
  id: string
  title: string
  ownerModule: 'OMS' | 'ERP' | 'WMS' | 'COMMON'
  direction: KbxIntegrationDirection
  transport: KbxIntegrationTransport
  criticality: KbxIntegrationCriticality
  sourceEvent: string
  target: string
  delivery: KbxIntegrationDelivery
  ordering: 'none' | 'per-aggregate'
  idempotency: 'none' | 'event-id' | 'business-key'
  timeoutMs: number
  shortRetry: KbxIntegrationShortRetryDefinition
  longRetry: KbxIntegrationLongRetryDefinition
  circuitBreaker: KbxIntegrationCircuitBreakerDefinition
  retryable: readonly string[]
  permanent: readonly string[]
  terminalAction: 'operations-exception' | 'dead-letter'
  userVisible: boolean
}

export interface KbxIntegrationStatusView {
  integrationId: string
  state: KbxIntegrationState
  label: string
  attemptCount?: number
  lastAttemptAt?: string
  nextRetryAt?: string
  detail?: string
  correlationId?: string
  retryAllowed?: boolean
}
