import '../../core/network/i_api_client.dart'; import 'models/calendar_event.dart'; abstract class CalendarEventRepository { Future> listByRange({ required DateTime startAt, required DateTime endAt, }); Future getById(String id); Future acceptSubscription(String itemId); Future rejectSubscription(String itemId); } class CalendarEventRepositoryImpl implements CalendarEventRepository { final IApiClient _apiClient; static const _prefix = '/api/v1/schedule-items'; CalendarEventRepositoryImpl(this._apiClient); @override Future> listByRange({ required DateTime startAt, required DateTime endAt, }) async { final start = Uri.encodeQueryComponent(startAt.toUtc().toIso8601String()); final end = Uri.encodeQueryComponent(endAt.toUtc().toIso8601String()); final response = await _apiClient.get>( '$_prefix?start_at=$start&end_at=$end', ); final data = response.data; if (data == null) { throw StateError('Invalid listByRange response: empty payload'); } return data .whereType>() .map(CalendarEvent.fromJson) .toList(growable: false); } @override Future getById(String id) async { final response = await _apiClient.get>('$_prefix/$id'); final event = response.data; if (event == null) { throw StateError('Invalid getById response: empty payload'); } return CalendarEvent.fromJson(event); } @override Future acceptSubscription(String itemId) { return _apiClient.post('$_prefix/$itemId/accept'); } @override Future rejectSubscription(String itemId) { return _apiClient.post('$_prefix/$itemId/reject'); } }