import 'package:dio/dio.dart'; import '../models/journal_day.dart'; import 'api_client.dart'; class JournalApi { final Dio _dio; const JournalApi(this._dio); /// GET /api/journal/today /// Creates today's journal conversation + daily prep on demand if absent, /// then returns the day payload. Future getToday() async { try { final response = await _dio.get('/api/journal/today'); return JournalDay.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } /// GET /api/journal/day/<iso_date> Future getDay(String isoDate) async { try { final response = await _dio.get('/api/journal/day/$isoDate'); return JournalDay.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } /// GET /api/journal/days — list of dates with journal content, newest first. Future> getDays() async { try { final response = await _dio.get('/api/journal/days'); final data = response.data as Map; final list = data['days'] as List; return list.map((e) => e as String).toList(); } on DioException catch (e) { throw dioToApp(e); } } /// POST /api/journal/trigger-prep — force-regenerate today's daily prep /// (or a specific day if [isoDate] is given). Future triggerPrep({String? isoDate}) async { try { final body = {}; if (isoDate != null) body['date'] = isoDate; await _dio.post('/api/journal/trigger-prep', data: body); } on DioException catch (e) { throw dioToApp(e); } } }