import type { AnalyticsEvent as BaseAnalyticsEvent } from '../types';

/**
 * Options for the @Track decorator
 */
export interface TrackOptions {
  /** Event name (defaults to method name) */
  event?: string;
  /** Event category */
  category?: string;
  /** Whether to include request body in event properties */
  includeBody?: boolean;
  /** Whether to include request params in event properties */
  includeParams?: boolean;
  /** Whether to include query params in event properties */
  includeQuery?: boolean;
  /** Custom properties extractor */
  extractProperties?: (context: TrackContext) => Record<string, unknown>;
}

/**
 * Context available when extracting properties
 */
export interface TrackContext {
  request: {
    method: string;
    url: string;
    path: string;
    body?: unknown;
    params?: Record<string, string>;
    query?: Record<string, string>;
    headers: Record<string, string | string[] | undefined>;
    ip?: string;
    user?: { id?: string; [key: string]: unknown };
  };
  response?: {
    statusCode: number;
  };
  executionTime?: number;
}

/**
 * Analytics event for NestJS
 */
export interface AnalyticsEvent extends Omit<BaseAnalyticsEvent, 'timestamp' | 'sessionId'> {
  timestamp?: string;
  sessionId?: string;
}

/**
 * Collector endpoint configuration
 */
export interface CollectorConfig {
  /** Collector service URL */
  url: string;
  /** API key for authentication */
  apiKey?: string;
  /** Request timeout in ms */
  timeout?: number;
  /** Number of retries */
  retries?: number;
}

/**
 * Batch configuration
 */
export interface BatchConfig {
  /** Maximum events to batch */
  maxSize?: number;
  /** Maximum time to wait before flushing (ms) */
  maxWait?: number;
}
