export interface User {
  id: string;
  email: string;
  firstName: string;
  lastName: string;
  createdAt: string;
  roles: ReadonlyArray<UserRole>;
  lastLoginAt?: string;
  isActive: boolean;
  preferences?: Readonly<UserPreferences>;
}

export type UserRole = 'admin' | 'user' | 'moderator';

export interface UserPreferences {
  readonly theme: 'light' | 'dark';
  readonly notifications: boolean;
  readonly language: string;
}

export interface LoginCredentials {
  readonly email: string;
  readonly password: string;
  readonly rememberMe?: boolean;
}

export interface SignupCredentials extends Omit<LoginCredentials, 'rememberMe'> {
  readonly firstName: string;
  readonly lastName: string;
  readonly confirmPassword: string;
}

export interface AuthState {
  readonly user: User | null;
  readonly isAuthenticated: boolean;
  readonly isLoading: boolean;
  readonly error: AuthError | null;
  readonly lastActivity?: Date;
}

export interface AuthError {
  readonly code: AuthErrorCode;
  readonly message: string;
  readonly details?: Readonly<Record<string, unknown>>;
  readonly timestamp: string;
  readonly statusCode?: number;
}

export type AuthErrorCode = 
  | 'INVALID_CREDENTIALS'
  | 'NETWORK_ERROR'
  | 'SERVER_ERROR'
  | 'VALIDATION_ERROR'
  | 'TOKEN_EXPIRED'
  | 'UNAUTHORIZED'
  | 'REQUEST_FAILED'
  | 'RATE_LIMIT_EXCEEDED'
  | 'ACCOUNT_LOCKED';

export interface ValidationErrors {
  readonly [key: string]: string | undefined;
  readonly email?: string;
  readonly password?: string;
  readonly firstName?: string;
  readonly lastName?: string;
  readonly confirmPassword?: string;
  readonly general?: string;
}

export interface AuthContextType extends Readonly<AuthState> {
  readonly login: (credentials: LoginCredentials) => Promise<void>;
  readonly signup: (credentials: SignupCredentials) => Promise<void>;
  readonly logout: () => Promise<void>;
  readonly clearError: () => void;
  readonly refreshToken: () => Promise<void>;
  readonly updateUser: (userData: Partial<User>) => Promise<void>;
  readonly resetPassword: (email: string) => Promise<void>;
  readonly validateSession: () => Promise<boolean>;
}