import 'package:dio/dio.dart'; import 'api_client.dart'; /// Result returned by POST /api/quick-capture. /// type is one of: "note", "task", "event", "todo" class CaptureResult { final String type; final String message; // human-readable summary from the server final bool fallback; // true when the server used a note as a fallback final int? id; final String title; const CaptureResult({ required this.type, required this.message, this.fallback = false, this.id, required this.title, }); factory CaptureResult.fromJson(Map json) { final data = json['data'] as Map? ?? {}; return CaptureResult( type: json['type'] as String? ?? 'note', message: json['message'] as String? ?? '', fallback: json['fallback'] as bool? ?? false, id: data['id'] as int?, title: data['title'] as String? ?? '', ); } } class QuickCaptureApi { final Dio _dio; const QuickCaptureApi(this._dio); Future capture(String text) async { try { final response = await _dio.post( '/api/quick-capture', data: {'text': text}, options: Options(receiveTimeout: const Duration(seconds: 120)), ); return CaptureResult.fromJson(response.data as Map); } on DioException catch (e) { throw dioToApp(e); } } }