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

export interface ReferralDoc {
  id: string;
  productId: string;
  referrerId: string;
  referrerEmail: string;
  referredUserId: string | null;
  referredEmail: string;
  status: 'pending' | 'signed_up' | 'subscribed' | 'rewarded';
  referrerRewardTokens: number;
  referredRewardTokens: number;
  referrerRewarded: boolean;
  referredRewarded: boolean;
  createdAt: string;
  completedAt: string | null;
}

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

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

  /** Returns a JWT access token, or null if not authenticated. */
  getAccessToken: () => string | null;

  /** Default reward tokens applied when creating referrals. */
  defaultRewardTokens?: { referrer: number; referred: number };
}

export interface ReferralClient {
  listMyReferrals(referrerId: string): Promise<{ referrals: ReferralDoc[]; count: number }>;
  getReferralStats(): Promise<{ total: number; completed: number; rewarded: number }>;
  createReferral(input: {
    referrerId: string;
    referrerEmail: string;
    referredEmail: string;
  }): Promise<ReferralDoc>;
  updateReferralStatus(
    id: string,
    referrerId: string,
    status: ReferralDoc['status']
  ): Promise<ReferralDoc>;
  getByEmail(email: string): Promise<ReferralDoc | null>;

  // Client-side helpers (pure TS, no network)
  buildShareLink(code: string): string;
  buildShareMessage(code: string, productName: string): string;
  calculateEarnedDays(conversions: number, daysPerReferral?: number): number;
}
