import 'package:freezed_annotation/freezed_annotation.dart'; import 'permissions.dart'; import 'user_preferences.dart'; part 'auth_state.freezed.dart'; /// Authentication state including user profile, roles, and preferences. @freezed sealed class AuthState with _$AuthState { const factory AuthState({ /// Whether user is authenticated. @Default(false) bool isAuthenticated, /// OIDC access token. String? accessToken, /// OIDC refresh token. String? refreshToken, /// Token expiration time. DateTime? expiresAt, /// Internal user ID (from core-api). String? userId, /// Authentik user ID. String? authentikId, /// User display name. String? userName, /// User email address. String? userEmail, /// User avatar URL. String? avatarUrl, /// User's permission roles. @Default([]) List roles, /// User preferences. UserPreferences? preferences, }) = _AuthState; const AuthState._(); /// Check if token is expired or will expire soon. bool get isTokenExpired { if (expiresAt == null) return true; // Consider expired if less than 1 minute remaining return DateTime.now().isAfter(expiresAt!.subtract(const Duration(minutes: 1))); } /// Check if user has the specified permission. bool hasPermission(Domain domain, Action action, {String category = 'general'}) { return roles.hasPermission(domain, action, category: category); } /// Check if user is a global admin. bool get isGlobalAdmin => roles.isGlobalAdmin; }