/**
 * Analytics client types.
 * Shared event types are imported from @lilith/domain-events.
 */

// Re-export shared types from domain-events for convenience
export type {
  AttributionData,
  ClientDeviceData,
  ViewEventData,
  EngagementEventData,
  ScrollDepth,
  ClickEventData,
  ScrollEventData,
  FunnelStepData,
  ResizeEventData,
  InteractionEvent,
  InteractionEventPayload,
} from '@lilith/domain-events'

// ─────────────────────────────────────────────────────────────────────────────
// Client-Specific Configuration Types
// ─────────────────────────────────────────────────────────────────────────────

import type { ScrollDepth } from '@lilith/domain-events'

/**
 * Scroll tracking configuration for the analytics provider.
 */
export interface ScrollTrackingConfig {
  enabled: boolean
  thresholds?: readonly ScrollDepth[] | ScrollDepth[]
  debounceMs?: number
}

/**
 * Analytics client configuration.
 *
 * CONSENT-FREE: This client uses in-memory session IDs only.
 * No localStorage/sessionStorage/cookies are used.
 */
export interface AnalyticsConfig {
  apiBaseUrl: string
  appName: string
  /** Write key sent as X-Write-Key header for collector authentication. Required in production. */
  writeKey?: string
  batchSize?: number
  batchInterval?: number
  enableDebugLogging?: boolean
  /** When false, all tracking methods become no-ops. Useful for dev mode. */
  enabled?: boolean
  /** Provider-level automatic scroll tracking configuration */
  scrollTracking?: ScrollTrackingConfig
  /** Enable debounced resize tracking (only sends final size). Default: false */
  trackResizes?: boolean
  /** Debounce delay for resize events in ms. Default: 1000 */
  resizeDebounceMs?: number
}

// ─────────────────────────────────────────────────────────────────────────────
// Client-Specific Batching Types
// ─────────────────────────────────────────────────────────────────────────────

import type { ViewEventData, EngagementEventData } from '@lilith/domain-events'

/**
 * Batched event structure for client-side queue.
 */
export interface BatchedEvent {
  type: 'view' | 'engagement'
  data: ViewEventData | EngagementEventData
  timestamp: number
}

// ─────────────────────────────────────────────────────────────────────────────
// React Context Types
// ─────────────────────────────────────────────────────────────────────────────

import type { InteractionEvent } from '@lilith/domain-events'

/**
 * Analytics context for React hooks.
 */
export interface AnalyticsContext {
  trackView: (data: Omit<ViewEventData, 'app' | 'sessionId'>) => void
  trackEngagement: (data: EngagementEventData) => void
  trackInteraction: (event: InteractionEvent) => void
  flush: () => Promise<void>
}
