export interface BaseUser {
  email: string;
  name: string;
  role: string;
  [key: string]: unknown;
}

export interface AuthContextValue<TUser extends BaseUser = BaseUser> {
  user: TUser | null;
  isAuthenticated: boolean;
  isLoading: boolean;
  error: string | null;
  success: string | null;
  login: (email: string, password: string) => Promise<boolean>;
  register: (email: string, password: string, displayName: string) => Promise<boolean>;
  logout: () => void;
  forgotPassword: (email: string) => Promise<boolean>;
  changePassword: (currentPassword: string, newPassword: string) => Promise<boolean>;
  deleteAccount: (password: string) => Promise<boolean>;
  updateUser: (updates: Partial<TUser>) => void;
  clearMessages: () => void;
}

export interface LoginResult<TUser extends BaseUser = BaseUser> {
  user: TUser;
  accessToken: string;
  refreshToken: string;
}

export interface AuthConfig<TUser extends BaseUser = BaseUser> {
  /** Base URL for auth API calls. Default: '/api'. */
  baseUrl?: string;
  storagePrefix: string;
  loginEndpoint: string;
  registerEndpoint?: string;
  forgotPasswordEndpoint?: string;
  changePasswordEndpoint?: string;
  deleteAccountEndpoint?: string;
  refreshEndpoint?: string;
  /** Token refresh interval in ms. Default: 45 * 60 * 1000 (45 minutes). */
  refreshIntervalMs?: number;
  mapLoginResponse: (data: unknown) => LoginResult<TUser>;
  onLoginFallback?: (
    email: string,
    password: string,
    error: string
  ) => Promise<LoginResult<TUser> | null>;
  /** Called once on mount to provide an initial session (e.g. from SSO cookies). Return null to fall through to localStorage. */
  onInit?: () => LoginResult<TUser> | null;
  onLogout?: () => void;
}
