/**
 * Types for @bytelyst/feature-flag-client.
 * Browser/React Native-safe — no Node.js dependencies.
 */

export interface FeatureFlagClientConfig {
  /** Platform-service base URL (e.g. "http://localhost:4003/api"). */
  baseUrl: string;

  /** Product identifier sent as x-product-id header. */
  productId: string;

  /** Platform string for the poll query (e.g. "mobile", "web"). */
  platform: string;

  /** Poll interval in milliseconds. Default: 5 minutes. */
  pollIntervalMs?: number;

  /** Optional persistent storage adapter for flag cache. */
  storage?: {
    getItem(key: string): string | null;
    setItem(key: string, value: string): void;
  };

  /** Optional storage key prefix. Default: productId. */
  storagePrefix?: string;
}

export interface FeatureFlagClient {
  /** Initialize the client: fetch flags immediately and start polling. */
  init(params?: { userId?: string }): Promise<void>;

  /** Check if a feature flag is enabled. Returns false if not found. */
  isEnabled(key: string): boolean;

  /** Get all currently cached flags. */
  getAllFlags(): Readonly<Record<string, boolean>>;

  /** Force a refresh of feature flags. */
  refresh(): Promise<void>;

  /** Stop polling and reset state. */
  stop(): void;
}
