import React from 'react';

import type { User } from '../../';

// User profile type
export type UserProfile = User;

// Auth configuration
export interface AuthConfig {
  apiUrl?: string;
  routes?: {
    auth?: string;
    defaultCallback?: string;
    defaultAuthCallback?: string;
  };
  onLogout?: () => void;
  onConfirm?: (options: {
    title: string;
    description: string;
    confirmationButtonText: string;
    cancellationButtonText: string;
    color: string;
  }) => Promise<{ confirmed: boolean }>;
}

// Auth context interface
export interface AuthContextType {
  user: UserProfile | null;
  isLoading: boolean;
  isAuthenticated: boolean;
  isAdminUser: boolean;
  loadCurrentProfile: (callerId?: string) => Promise<void>;
  checkAuthAndRedirect: () => Promise<void>;

  // Token Methods
  getToken: () => string | null;
  getRefreshToken: () => string | null;

  // Email Methods
  getSavedEmail: () => string | null;
  saveEmail: (email: string) => void;
  clearSavedEmail: () => void;

  // Phone Methods
  getSavedPhone: () => string | null;
  savePhone: (phone: string) => void;
  clearSavedPhone: () => void;

  // OTP Methods - Multi-channel support
  requestOTP: (identifier: string, channel?: 'email' | 'phone', sourceUrl?: string) => Promise<{ success: boolean; message: string }>;
  verifyOTP: (identifier: string, otpCode: string, channel?: 'email' | 'phone', sourceUrl?: string, redirectUrl?: string, skipRedirect?: boolean) => Promise<{
    success: boolean;
    message: string;
    user?: UserProfile;
    requires_2fa?: boolean;
    session_id?: string | null;
    should_prompt_2fa?: boolean;
  }>;
  refreshToken: () => Promise<{ success: boolean; message: string }>;
  logout: () => Promise<void>;

  // Redirect URL Methods - for saving URL before auth redirect
  saveRedirectUrl: (url: string) => void;
  getRedirectUrl: () => string;
  clearRedirectUrl: () => void;
  hasRedirectUrl: () => boolean;
}

// Provider props
export interface AuthProviderProps {
  children: React.ReactNode;
  config?: AuthConfig;
} 