/**
 * Sleek SDK - TypeScript Declarations
 */

export interface SleekUserManagerOptions {
  storageKey?: string;
  useLocalStorage?: boolean;
  useSessionStorage?: boolean;
  cookieName?: string;
  cookieExpireDays?: number;
  useDeviceFingerprint?: boolean;
  fallbackToFingerprint?: boolean;
}

export interface UserContext {
  userId: string;
  isAnonymous: boolean;
  userProperties: Record<string, any>;
  sessionId: string | null;
  deviceInfo: Record<string, any>;
}

export interface AssignmentInfo {
  variant: string;
  assigned_at: string;
  expires_at?: string;
  is_expired: boolean;
  expires_soon: boolean;
  session_id: string | null;
}

export interface SleekSDKOptions {
  apiUrl?: string;
  timeout?: number;
  requestTimeout?: number;
  retryAttempts?: number;
  batchEvents?: boolean;
  batchSize?: number;
  flushInterval?: number;
  autoRefresh?: boolean;
  gracefulFallback?: boolean;
  enableLogging?: boolean;
  headers?: Record<string, string>;
  userManager?: SleekUserManagerOptions;
}

export interface SleekSDK {
  // Core SDK methods
  getVariant(experimentId: string, forceRefresh?: boolean): Promise<string>;
  getVariantConfig(
    experimentId: string,
    forceRefresh?: boolean
  ): Promise<Record<string, any>>;
  getAssignmentInfo(experimentId: string): AssignmentInfo | null;
  isAssignmentExpired(experimentId: string): boolean;
  isAssignmentExpiringSoon(
    experimentId: string,
    minutesBeforeExpiry?: number
  ): boolean;
  refreshAssignment(experimentId: string): Promise<string>;
  track(
    experimentId: string,
    eventName: string,
    properties?: Record<string, any>
  ): void;
  trackConversion(experimentId: string, properties?: Record<string, any>): void;
  flushEvents(): Promise<void>;
  clearAssignments(): void;
  getAssignments(): Record<string, string>;

  // User management methods
  setUser(userId: string, properties?: Record<string, any>): string;
  clearUser(): void;
  getUserId(): string;
  getUserContext(): UserContext;
  isAnonymous(): boolean;

  // Utility methods
  getSessionId(): string | null;
  cleanup(): void;
}

export class SleekUserManager {
  constructor(options?: SleekUserManagerOptions);
  setAuthenticatedUser(
    userId: string,
    userProperties?: Record<string, any>
  ): string;
  getUserId(): string;
  generateAnonymousId(): string;
  storeUserId(userId: string): void;
  getStoredUserId(): string | null;
  clearUser(): void;
  getUserContext(): UserContext;
  getSessionId(): string | null;
  getDeviceInfo(): Record<string, any>;
}

// Factory functions
export function createSleekSDK(
  apiUrl: string,
  userIdOrManager?: string | SleekUserManager | null,
  options?: SleekSDKOptions
): SleekSDK;

export function createAnonymousSleek(
  apiUrl: string,
  options?: SleekSDKOptions
): SleekSDK;

export function createAuthenticatedSleek(
  apiUrl: string,
  userId: string,
  userProperties?: Record<string, any>,
  options?: SleekSDKOptions
): SleekSDK;

// Default export
export default createSleekSDK;
