import 'package:dio/dio.dart'; import '../models/calendar_event.dart'; import 'api_client.dart'; class EventsApi { final Dio _dio; const EventsApi(this._dio); /// GET /api/events?from={iso}&to={iso} Future> getEvents(DateTime from, DateTime to) async { try { final response = await _dio.get( '/api/events', queryParameters: { 'from': from.toUtc().toIso8601String(), 'to': to.toUtc().toIso8601String(), }, ); final list = response.data as List; return list .map((e) => CalendarEvent.fromJson(e as Map)) .toList(); } on DioException catch (e) { throw dioToApp(e); } } /// POST /api/events Future createEvent(Map payload) async { try { final response = await _dio.post('/api/events', data: payload); return CalendarEvent.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } /// PATCH /api/events/{id} Future updateEvent( int id, Map fields) async { try { final response = await _dio.patch('/api/events/$id', data: fields); return CalendarEvent.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } /// DELETE /api/events/{id} Future deleteEvent(int id) async { try { await _dio.delete('/api/events/$id'); } on DioException catch (e) { throw dioToApp(e); } } }