import 'package:dio/dio.dart'; import '../models/dashboard_stats_model.dart'; import '../../../../core/network/dio_client.dart'; import '../../../../core/error/exceptions.dart'; abstract class DashboardRemoteDataSource { Future getDashboardData(String organizationId, String userId); Future getDashboardStats(String organizationId, String userId); Future> getRecentActivities(String organizationId, String userId, {int limit = 10}); Future> getUpcomingEvents(String organizationId, String userId, {int limit = 5}); } class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource { final DioClient dioClient; DashboardRemoteDataSourceImpl({required this.dioClient}); @override Future getDashboardData(String organizationId, String userId) async { try { final response = await dioClient.get( '/api/v1/dashboard/data', queryParameters: { 'organizationId': organizationId, 'userId': userId, }, ); if (response.statusCode == 200) { return DashboardDataModel.fromJson(response.data); } else { throw ServerException('Failed to load dashboard data: ${response.statusCode}'); } } on DioException catch (e) { throw ServerException('Network error: ${e.message}'); } catch (e) { throw ServerException('Unexpected error: $e'); } } @override Future getDashboardStats(String organizationId, String userId) async { try { final response = await dioClient.get( '/api/v1/dashboard/stats', queryParameters: { 'organizationId': organizationId, 'userId': userId, }, ); if (response.statusCode == 200) { return DashboardStatsModel.fromJson(response.data); } else { throw ServerException('Failed to load dashboard stats: ${response.statusCode}'); } } on DioException catch (e) { throw ServerException('Network error: ${e.message}'); } catch (e) { throw ServerException('Unexpected error: $e'); } } @override Future> getRecentActivities( String organizationId, String userId, { int limit = 10, }) async { try { final response = await dioClient.get( '/api/v1/dashboard/activities', queryParameters: { 'organizationId': organizationId, 'userId': userId, 'limit': limit, }, ); if (response.statusCode == 200) { final List data = response.data['activities'] ?? []; return data.map((json) => RecentActivityModel.fromJson(json)).toList(); } else { throw ServerException('Failed to load recent activities: ${response.statusCode}'); } } on DioException catch (e) { throw ServerException('Network error: ${e.message}'); } catch (e) { throw ServerException('Unexpected error: $e'); } } @override Future> getUpcomingEvents( String organizationId, String userId, { int limit = 5, }) async { try { final response = await dioClient.get( '/api/v1/dashboard/events/upcoming', queryParameters: { 'organizationId': organizationId, 'userId': userId, 'limit': limit, }, ); if (response.statusCode == 200) { final List data = response.data['events'] ?? []; return data.map((json) => UpcomingEventModel.fromJson(json)).toList(); } else { throw ServerException('Failed to load upcoming events: ${response.statusCode}'); } } on DioException catch (e) { throw ServerException('Network error: ${e.message}'); } catch (e) { throw ServerException('Unexpected error: $e'); } } }