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

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

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

  /** Storage adapter for tokens. Defaults to localStorage if available. */
  storage?: TokenStorage;

  /** Optional prefix for storage keys. Default: product ID. */
  storagePrefix?: string;

  /** Request timeout in milliseconds. Default: 15000. */
  timeoutMs?: number;
}

export interface TokenStorage {
  getItem(key: string): string | null;
  setItem(key: string, value: string): void;
  removeItem(key: string): void;
}

export interface AuthUser {
  id: string;
  email: string;
  displayName: string;
  role: string;
  plan: string;
}

export interface AuthResult {
  accessToken: string;
  refreshToken: string;
  user: AuthUser;
}

export interface AuthClient {
  // ── Token management ────────────────────────────
  getAccessToken(): string | null;
  getRefreshToken(): string | null;
  setTokens(accessToken: string, refreshToken: string): void;
  clearTokens(): void;
  isAuthenticated(): boolean;

  // ── Auth operations ─────────────────────────────
  login(email: string, password: string): Promise<AuthResult>;
  register(email: string, password: string, displayName: string): Promise<AuthResult>;
  getMe(): Promise<AuthUser>;
  refreshAccessToken(): Promise<boolean>;

  // ── Password management ─────────────────────────
  forgotPassword(email: string): Promise<{ message: string }>;
  resetPassword(token: string, newPassword: string): Promise<{ message: string }>;
  changePassword(currentPassword: string, newPassword: string): Promise<{ message: string }>;

  // ── Account management ──────────────────────────
  deleteAccount(password: string): Promise<{ message: string }>;

  // ── Email verification ──────────────────────────
  verifyEmail(token: string): Promise<{ message: string }>;
  resendVerification(email: string): Promise<{ message: string }>;
}
