import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../core/network/api_client.dart'; import '../../../core/storage/secure_storage.dart'; import '../data/datasources/auth_remote_datasource.dart'; import '../data/repositories/auth_repository_impl.dart'; import '../domain/repositories/auth_repository.dart'; import '../domain/usecases/login_usecase.dart'; import '../presentation/providers/auth_provider.dart'; /// Dependency injection setup for authentication feature /// /// This file contains all Riverpod providers for the auth feature /// following clean architecture principles // ==================== Data Layer ==================== /// Provider for AuthRemoteDataSource /// /// Depends on ApiClient from core final authRemoteDataSourceProvider = Provider((ref) { // TODO: Replace with actual ApiClient provider when available final apiClient = ApiClient(SecureStorage()); return AuthRemoteDataSourceImpl(apiClient); }); /// Provider for SecureStorage /// /// Singleton instance final secureStorageProvider = Provider((ref) { return SecureStorage(); }); // ==================== Domain Layer ==================== /// Provider for AuthRepository /// /// Depends on AuthRemoteDataSource and SecureStorage final authRepositoryProvider = Provider((ref) { final remoteDataSource = ref.watch(authRemoteDataSourceProvider); final secureStorage = ref.watch(secureStorageProvider); return AuthRepositoryImpl( remoteDataSource: remoteDataSource, secureStorage: secureStorage, ); }); /// Provider for LoginUseCase final loginUseCaseProvider = Provider((ref) { final repository = ref.watch(authRepositoryProvider); return LoginUseCase(repository); }); /// Provider for LogoutUseCase final logoutUseCaseProvider = Provider((ref) { final repository = ref.watch(authRepositoryProvider); return LogoutUseCase(repository); }); /// Provider for CheckAuthStatusUseCase final checkAuthStatusUseCaseProvider = Provider((ref) { final repository = ref.watch(authRepositoryProvider); return CheckAuthStatusUseCase(repository); }); /// Provider for GetCurrentUserUseCase final getCurrentUserUseCaseProvider = Provider((ref) { final repository = ref.watch(authRepositoryProvider); return GetCurrentUserUseCase(repository); }); /// Provider for RefreshTokenUseCase final refreshTokenUseCaseProvider = Provider((ref) { final repository = ref.watch(authRepositoryProvider); return RefreshTokenUseCase(repository); }); // ==================== Presentation Layer ==================== /// Provider for AuthNotifier (State Management) /// /// This is the main provider that UI will interact with final authProvider = StateNotifierProvider((ref) { final loginUseCase = ref.watch(loginUseCaseProvider); final logoutUseCase = ref.watch(logoutUseCaseProvider); final checkAuthStatusUseCase = ref.watch(checkAuthStatusUseCaseProvider); final getCurrentUserUseCase = ref.watch(getCurrentUserUseCaseProvider); return AuthNotifier( loginUseCase: loginUseCase, logoutUseCase: logoutUseCase, checkAuthStatusUseCase: checkAuthStatusUseCase, getCurrentUserUseCase: getCurrentUserUseCase, ); }); // ==================== Convenience Providers ==================== /// Provider to check if user is authenticated /// /// Returns boolean indicating authentication status final isAuthenticatedProvider = Provider((ref) { final authState = ref.watch(authProvider); return authState.isAuthenticated; }); /// Provider to get current user /// /// Returns UserEntity if authenticated, null otherwise final currentUserProvider = Provider((ref) { final authState = ref.watch(authProvider); return authState.user; }); /// Provider to check if auth operation is loading final isAuthLoadingProvider = Provider((ref) { final authState = ref.watch(authProvider); return authState.isLoading; }); /// Provider to get auth error message final authErrorProvider = Provider((ref) { final authState = ref.watch(authProvider); return authState.error; });