LifeMate — Personal, Family & Learning Companion
fix/backend-request-safety
chore/phase1-repository-cleanup
deploy/stable-web-apk
deployment-static
design/mobile-accessibility-v2
design/mobile-navigation-review
docs/child-education-access-decision
docs/offline-data-rescue-options
docs/owner-guide-and-delivery-plan
docs/phase1-policy-options
docs/public-review-live-2026-10-15
feat/aparat-learning-library
feat/child-device-safety
feat/child-identity-schema
feat/flutter-mobile-navigation
feat/learning-content-operations
feat/local-signing-preflight
feat/online-family-stage0
feat/personal-encrypted-recovery
feat/private-planner-series-api
feat/public-review-page
feat/standalone-weekly-planner
feat/weekly-planner-android
final-feature-1/iran-family-school
fix/auth-abuse-expiry-safety
fix/auth-expiry-after-lock
fix/backend-request-safety
fix/lifeguide-bootstrap-naming-ci
fix/lifeguide-pages-qa-base-preflight
fix/lifeguide-qa-pages-env-deployment
fix/local-task-persistence
fix/managed-child-session-boundary
fix/personal-jalali-dates
fix/personal-notification-controls
fix/personal-upgrade-delivery-guard
fix/sms-approval-gates
fix/study-duration-display
infra/cloudflare-neon-migration
infra/lifeguide-cloudflare-qa
infra/lifeguide-github-pages-qa
infra/lifeguide-supabase-qa
main
phase-1/foundation-completion
phase-2/product-foundation-identity
phase-3/planner-school-family-core
phase-4/ai-learning-wellbeing
phase-5/hardening-observability-release
test/android-reminder-acceptance
test/personal-notification-settings
test/personal-recovery-acceptance
test/role-entry-apk
| 1 | import 'dart:convert'; |
| 2 | |
| 3 | import 'package:http/http.dart' as http; |
| 4 | |
| 5 | abstract class IdentityApi { |
| 6 | String? get accessToken; |
| 7 | |
| 8 | Future<void> register({ |
| 9 | required String displayName, |
| 10 | required String email, |
| 11 | required String password, |
| 12 | }); |
| 13 | |
| 14 | Future<void> verifyEmail(String token); |
| 15 | Future<void> login(String email, String password); |
| 16 | Future<void> forgotPassword(String email); |
| 17 | Future<void> resetPassword(String token, String newPassword); |
| 18 | Future<void> changePassword(String currentPassword, String newPassword); |
| 19 | Future<Map<String, dynamic>> getProfile(); |
| 20 | Future<Map<String, dynamic>> updateProfile({ |
| 21 | String? displayName, |
| 22 | String? birthDate, |
| 23 | String? themePreference, |
| 24 | }); |
| 25 | Future<List<Map<String, dynamic>>> listFamilies(); |
| 26 | Future<List<Map<String, dynamic>>> listFamilyMembers(String familyId); |
| 27 | Future<Map<String, dynamic>> createFamily(String name, {String? role}); |
| 28 | Future<void> inviteMember({ |
| 29 | required String familyId, |
| 30 | required String email, |
| 31 | required String role, |
| 32 | String? themePreference, |
| 33 | }); |
| 34 | Future<void> acceptInvitation(String token); |
| 35 | Future<void> setGuardian({ |
| 36 | required String familyId, |
| 37 | required String guardianUserId, |
| 38 | required String minorUserId, |
| 39 | }); |
| 40 | |
| 41 | Future<List<Map<String, dynamic>>> getToday({ |
| 42 | required DateTime from, |
| 43 | required DateTime to, |
| 44 | }); |
| 45 | Future<List<Map<String, dynamic>>> listPlanItems({ |
| 46 | DateTime? from, |
| 47 | DateTime? to, |
| 48 | String? kind, |
| 49 | }); |
| 50 | Future<Map<String, dynamic>> createPlanItem(Map<String, dynamic> data); |
| 51 | Future<Map<String, dynamic>> updatePlanItem( |
| 52 | String itemId, |
| 53 | Map<String, dynamic> data, |
| 54 | ); |
| 55 | Future<List<Map<String, dynamic>>> listLifeContexts(); |
| 56 | Future<Map<String, dynamic>> createLifeContext({ |
| 57 | required String kind, |
| 58 | required String title, |
| 59 | }); |
| 60 | Future<Map<String, dynamic>> createAcademicYear(Map<String, dynamic> data); |
| 61 | Future<Map<String, dynamic>> createAcademicTerm( |
| 62 | String yearId, |
| 63 | Map<String, dynamic> data, |
| 64 | ); |
| 65 | Future<Map<String, dynamic>> createSubject( |
| 66 | String termId, |
| 67 | Map<String, dynamic> data, |
| 68 | ); |
| 69 | Future<Map<String, dynamic>> createClassSession( |
| 70 | String subjectId, |
| 71 | Map<String, dynamic> data, |
| 72 | ); |
| 73 | Future<Map<String, dynamic>> getSchoolOverview(String studentUserId); |
| 74 | Future<List<Map<String, dynamic>>> getTimetable(String studentUserId); |
| 75 | Future<Map<String, dynamic>> setGrade( |
| 76 | String itemId, { |
| 77 | required num points, |
| 78 | required num outOf, |
| 79 | }); |
| 80 | Future<List<Map<String, dynamic>>> claimDueReminders(); |
| 81 | Future<List<Map<String, dynamic>>> getFamilyCalendar(String familyId); |
| 82 | Future<Map<String, dynamic>> getChildSupportSummary( |
| 83 | String familyId, |
| 84 | String studentUserId, |
| 85 | ); |
| 86 | Future<Map<String, dynamic>> submitSyncMutations( |
| 87 | List<Map<String, dynamic>> mutations, |
| 88 | ); |
| 89 | |
| 90 | Future<Map<String, dynamic>> createLearningGoal({ |
| 91 | required String title, |
| 92 | String? target, |
| 93 | String? subjectId, |
| 94 | }); |
| 95 | Future<List<Map<String, dynamic>>> listLearningGoals(); |
| 96 | Future<Map<String, dynamic>> createLearningCheckin({ |
| 97 | String? learningGoalId, |
| 98 | required int confidence, |
| 99 | required int difficulty, |
| 100 | String? note, |
| 101 | }); |
| 102 | Future<Map<String, dynamic>> createWellbeingCheckin({ |
| 103 | required int mood, |
| 104 | required int energy, |
| 105 | required int stress, |
| 106 | String? note, |
| 107 | String visibility, |
| 108 | }); |
| 109 | Future<List<Map<String, dynamic>>> listWellbeingCheckins(); |
| 110 | Future<Map<String, dynamic>> createAiSession(String kind); |
| 111 | Future<Map<String, dynamic>> sendAiMessage( |
| 112 | String sessionId, |
| 113 | String message, |
| 114 | ); |
| 115 | Future<Map<String, dynamic>> getGuardianWellbeingSummary( |
| 116 | String familyId, |
| 117 | String minorUserId, |
| 118 | ); |
| 119 | Future<Map<String, dynamic>> requestFamilyGuidance( |
| 120 | String familyId, |
| 121 | String minorUserId, |
| 122 | String question, |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | class ApiException implements Exception { |
| 127 | const ApiException(this.statusCode, this.code); |
| 128 | final int statusCode; |
| 129 | final String code; |
| 130 | |
| 131 | @override |
| 132 | String toString() => 'ApiException($statusCode, $code)'; |
| 133 | } |
| 134 | |
| 135 | class HttpIdentityApi implements IdentityApi { |
| 136 | HttpIdentityApi({ |
| 137 | String? baseUrl, |
| 138 | http.Client? client, |
| 139 | }) : baseUrl = baseUrl ?? |
| 140 | const String.fromEnvironment( |
| 141 | 'LIFEMATE_API_URL', |
| 142 | defaultValue: 'http://localhost:8080', |
| 143 | ), |
| 144 | _client = client ?? http.Client(); |
| 145 | |
| 146 | final String baseUrl; |
| 147 | final http.Client _client; |
| 148 | |
| 149 | @override |
| 150 | String? accessToken; |
| 151 | String? _refreshToken; |
| 152 | |
| 153 | Uri _uri(String path) => Uri.parse('$baseUrl$path'); |
| 154 | |
| 155 | Map<String, String> _headers({bool auth = false}) => { |
| 156 | 'content-type': 'application/json', |
| 157 | if (auth && accessToken != null) 'authorization': 'Bearer $accessToken', |
| 158 | }; |
| 159 | |
| 160 | Future<Map<String, dynamic>> _json( |
| 161 | String method, |
| 162 | String path, { |
| 163 | Map<String, dynamic>? body, |
| 164 | bool auth = false, |
| 165 | bool retry = true, |
| 166 | }) async { |
| 167 | final request = http.Request(method, _uri(path)) |
| 168 | ..headers.addAll(_headers(auth: auth)); |
| 169 | if (body != null) request.body = jsonEncode(body); |
| 170 | |
| 171 | final streamed = await _client.send(request); |
| 172 | final response = await http.Response.fromStream(streamed); |
| 173 | |
| 174 | if (response.statusCode == 401 && auth && retry && _refreshToken != null) { |
| 175 | await _refresh(); |
| 176 | return _json(method, path, body: body, auth: auth, retry: false); |
| 177 | } |
| 178 | |
| 179 | if (response.statusCode < 200 || response.statusCode >= 300) { |
| 180 | var code = 'request_failed'; |
| 181 | if (response.body.isNotEmpty) { |
| 182 | try { |
| 183 | code = (jsonDecode(response.body) as Map<String, dynamic>)['error'] |
| 184 | ?.toString() ?? |
| 185 | code; |
| 186 | } catch (_) {} |
| 187 | } |
| 188 | throw ApiException(response.statusCode, code); |
| 189 | } |
| 190 | |
| 191 | if (response.body.isEmpty) return <String, dynamic>{}; |
| 192 | return jsonDecode(response.body) as Map<String, dynamic>; |
| 193 | } |
| 194 | |
| 195 | Future<void> _refresh() async { |
| 196 | final token = _refreshToken; |
| 197 | if (token == null) throw const ApiException(401, 'session_expired'); |
| 198 | final result = await _json( |
| 199 | 'POST', |
| 200 | '/v1/auth/refresh', |
| 201 | body: {'refreshToken': token}, |
| 202 | retry: false, |
| 203 | ); |
| 204 | accessToken = result['accessToken']?.toString(); |
| 205 | _refreshToken = result['refreshToken']?.toString(); |
| 206 | } |
| 207 | |
| 208 | @override |
| 209 | Future<void> register({ |
| 210 | required String displayName, |
| 211 | required String email, |
| 212 | required String password, |
| 213 | }) async { |
| 214 | await _json('POST', '/v1/auth/register', body: { |
| 215 | 'displayName': displayName, |
| 216 | 'email': email, |
| 217 | 'password': password, |
| 218 | }); |
| 219 | } |
| 220 | |
| 221 | @override |
| 222 | Future<void> verifyEmail(String token) async { |
| 223 | await _json('POST', '/v1/auth/verify-email', body: {'token': token}); |
| 224 | } |
| 225 | |
| 226 | @override |
| 227 | Future<void> login(String email, String password) async { |
| 228 | final result = await _json('POST', '/v1/auth/login', body: { |
| 229 | 'email': email, |
| 230 | 'password': password, |
| 231 | }); |
| 232 | accessToken = result['accessToken']?.toString(); |
| 233 | _refreshToken = result['refreshToken']?.toString(); |
| 234 | } |
| 235 | |
| 236 | @override |
| 237 | Future<void> forgotPassword(String email) async { |
| 238 | await _json('POST', '/v1/auth/forgot-password', body: {'email': email}); |
| 239 | } |
| 240 | |
| 241 | @override |
| 242 | Future<void> resetPassword(String token, String newPassword) async { |
| 243 | await _json('POST', '/v1/auth/reset-password', body: { |
| 244 | 'token': token, |
| 245 | 'newPassword': newPassword, |
| 246 | }); |
| 247 | } |
| 248 | |
| 249 | @override |
| 250 | Future<void> changePassword( |
| 251 | String currentPassword, |
| 252 | String newPassword, |
| 253 | ) async { |
| 254 | await _json('POST', '/v1/auth/change-password', auth: true, body: { |
| 255 | 'currentPassword': currentPassword, |
| 256 | 'newPassword': newPassword, |
| 257 | }); |
| 258 | } |
| 259 | |
| 260 | @override |
| 261 | Future<Map<String, dynamic>> getProfile() => |
| 262 | _json('GET', '/v1/profile', auth: true); |
| 263 | |
| 264 | @override |
| 265 | Future<Map<String, dynamic>> updateProfile({ |
| 266 | String? displayName, |
| 267 | String? birthDate, |
| 268 | String? themePreference, |
| 269 | }) => |
| 270 | _json('PATCH', '/v1/profile', auth: true, body: { |
| 271 | if (displayName != null) 'displayName': displayName, |
| 272 | if (birthDate != null) 'birthDate': birthDate, |
| 273 | if (themePreference != null) 'themePreference': themePreference, |
| 274 | }); |
| 275 | |
| 276 | @override |
| 277 | Future<List<Map<String, dynamic>>> listFamilies() async { |
| 278 | final result = await _json('GET', '/v1/families', auth: true); |
| 279 | final families = (result['families'] as List<dynamic>? ?? const []); |
| 280 | return families |
| 281 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 282 | .toList(); |
| 283 | } |
| 284 | |
| 285 | @override |
| 286 | Future<List<Map<String, dynamic>>> listFamilyMembers(String familyId) async { |
| 287 | final result = await _json( |
| 288 | 'GET', |
| 289 | '/v1/families/$familyId/members', |
| 290 | auth: true, |
| 291 | ); |
| 292 | final members = (result['members'] as List<dynamic>? ?? const []); |
| 293 | return members |
| 294 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 295 | .toList(); |
| 296 | } |
| 297 | |
| 298 | @override |
| 299 | Future<Map<String, dynamic>> createFamily( |
| 300 | String name, { |
| 301 | String? role, |
| 302 | }) => |
| 303 | _json('POST', '/v1/families', auth: true, body: { |
| 304 | 'name': name, |
| 305 | if (role != null) 'role': role, |
| 306 | }); |
| 307 | |
| 308 | @override |
| 309 | Future<void> inviteMember({ |
| 310 | required String familyId, |
| 311 | required String email, |
| 312 | required String role, |
| 313 | String? themePreference, |
| 314 | }) async { |
| 315 | await _json( |
| 316 | 'POST', |
| 317 | '/v1/families/$familyId/invitations', |
| 318 | auth: true, |
| 319 | body: { |
| 320 | 'email': email, |
| 321 | 'role': role, |
| 322 | if (themePreference != null) 'themePreference': themePreference, |
| 323 | }, |
| 324 | ); |
| 325 | } |
| 326 | |
| 327 | @override |
| 328 | Future<void> acceptInvitation(String token) async { |
| 329 | await _json( |
| 330 | 'POST', |
| 331 | '/v1/invitations/accept', |
| 332 | auth: true, |
| 333 | body: {'token': token}, |
| 334 | ); |
| 335 | } |
| 336 | |
| 337 | @override |
| 338 | Future<void> setGuardian({ |
| 339 | required String familyId, |
| 340 | required String guardianUserId, |
| 341 | required String minorUserId, |
| 342 | }) async { |
| 343 | await _json( |
| 344 | 'POST', |
| 345 | '/v1/families/$familyId/guardians', |
| 346 | auth: true, |
| 347 | body: { |
| 348 | 'guardianUserId': guardianUserId, |
| 349 | 'minorUserId': minorUserId, |
| 350 | }, |
| 351 | ); |
| 352 | } |
| 353 | @override |
| 354 | Future<List<Map<String, dynamic>>> getToday({ |
| 355 | required DateTime from, |
| 356 | required DateTime to, |
| 357 | }) async { |
| 358 | final result = await _json( |
| 359 | 'GET', |
| 360 | '/v1/today?from=${Uri.encodeQueryComponent(from.toUtc().toIso8601String())}&to=${Uri.encodeQueryComponent(to.toUtc().toIso8601String())}', |
| 361 | auth: true, |
| 362 | ); |
| 363 | return (result['items'] as List<dynamic>? ?? const []) |
| 364 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 365 | .toList(); |
| 366 | } |
| 367 | |
| 368 | @override |
| 369 | Future<List<Map<String, dynamic>>> listPlanItems({ |
| 370 | DateTime? from, |
| 371 | DateTime? to, |
| 372 | String? kind, |
| 373 | }) async { |
| 374 | final params = <String, String>{}; |
| 375 | if (from != null) params['from'] = from.toUtc().toIso8601String(); |
| 376 | if (to != null) params['to'] = to.toUtc().toIso8601String(); |
| 377 | if (kind != null) params['kind'] = kind; |
| 378 | final suffix = params.isEmpty ? '' : '?${Uri(queryParameters: params).query}'; |
| 379 | final result = await _json('GET', '/v1/plan-items$suffix', auth: true); |
| 380 | return (result['items'] as List<dynamic>? ?? const []) |
| 381 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 382 | .toList(); |
| 383 | } |
| 384 | |
| 385 | @override |
| 386 | Future<Map<String, dynamic>> createPlanItem(Map<String, dynamic> data) => |
| 387 | _json('POST', '/v1/plan-items', auth: true, body: data); |
| 388 | |
| 389 | @override |
| 390 | Future<Map<String, dynamic>> updatePlanItem( |
| 391 | String itemId, |
| 392 | Map<String, dynamic> data, |
| 393 | ) => |
| 394 | _json('PATCH', '/v1/plan-items/$itemId', auth: true, body: data); |
| 395 | |
| 396 | @override |
| 397 | Future<List<Map<String, dynamic>>> listLifeContexts() async { |
| 398 | final result = await _json('GET', '/v1/life-contexts', auth: true); |
| 399 | return (result['contexts'] as List<dynamic>? ?? const []) |
| 400 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 401 | .toList(); |
| 402 | } |
| 403 | |
| 404 | @override |
| 405 | Future<Map<String, dynamic>> createLifeContext({ |
| 406 | required String kind, |
| 407 | required String title, |
| 408 | }) => |
| 409 | _json( |
| 410 | 'POST', |
| 411 | '/v1/life-contexts', |
| 412 | auth: true, |
| 413 | body: {'kind': kind, 'title': title}, |
| 414 | ); |
| 415 | |
| 416 | @override |
| 417 | Future<Map<String, dynamic>> createAcademicYear( |
| 418 | Map<String, dynamic> data, |
| 419 | ) => |
| 420 | _json('POST', '/v1/school/years', auth: true, body: data); |
| 421 | |
| 422 | @override |
| 423 | Future<Map<String, dynamic>> createAcademicTerm( |
| 424 | String yearId, |
| 425 | Map<String, dynamic> data, |
| 426 | ) => |
| 427 | _json( |
| 428 | 'POST', |
| 429 | '/v1/school/years/$yearId/terms', |
| 430 | auth: true, |
| 431 | body: data, |
| 432 | ); |
| 433 | |
| 434 | @override |
| 435 | Future<Map<String, dynamic>> createSubject( |
| 436 | String termId, |
| 437 | Map<String, dynamic> data, |
| 438 | ) => |
| 439 | _json( |
| 440 | 'POST', |
| 441 | '/v1/school/terms/$termId/subjects', |
| 442 | auth: true, |
| 443 | body: data, |
| 444 | ); |
| 445 | |
| 446 | @override |
| 447 | Future<Map<String, dynamic>> createClassSession( |
| 448 | String subjectId, |
| 449 | Map<String, dynamic> data, |
| 450 | ) => |
| 451 | _json( |
| 452 | 'POST', |
| 453 | '/v1/school/subjects/$subjectId/classes', |
| 454 | auth: true, |
| 455 | body: data, |
| 456 | ); |
| 457 | |
| 458 | @override |
| 459 | Future<Map<String, dynamic>> getSchoolOverview(String studentUserId) => |
| 460 | _json('GET', '/v1/school/$studentUserId/overview', auth: true); |
| 461 | |
| 462 | @override |
| 463 | Future<List<Map<String, dynamic>>> getTimetable(String studentUserId) async { |
| 464 | final result = await _json( |
| 465 | 'GET', |
| 466 | '/v1/school/$studentUserId/timetable', |
| 467 | auth: true, |
| 468 | ); |
| 469 | return (result['classes'] as List<dynamic>? ?? const []) |
| 470 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 471 | .toList(); |
| 472 | } |
| 473 | |
| 474 | @override |
| 475 | Future<Map<String, dynamic>> setGrade( |
| 476 | String itemId, { |
| 477 | required num points, |
| 478 | required num outOf, |
| 479 | }) => |
| 480 | _json( |
| 481 | 'PATCH', |
| 482 | '/v1/school/plan-items/$itemId/grade', |
| 483 | auth: true, |
| 484 | body: {'points': points, 'outOf': outOf}, |
| 485 | ); |
| 486 | |
| 487 | @override |
| 488 | Future<List<Map<String, dynamic>>> claimDueReminders() async { |
| 489 | final result = await _json( |
| 490 | 'POST', |
| 491 | '/v1/reminders/claim-due', |
| 492 | auth: true, |
| 493 | body: {'limit': 20}, |
| 494 | ); |
| 495 | return (result['reminders'] as List<dynamic>? ?? const []) |
| 496 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 497 | .toList(); |
| 498 | } |
| 499 | |
| 500 | @override |
| 501 | Future<List<Map<String, dynamic>>> getFamilyCalendar(String familyId) async { |
| 502 | final result = await _json( |
| 503 | 'GET', |
| 504 | '/v1/families/$familyId/calendar', |
| 505 | auth: true, |
| 506 | ); |
| 507 | return (result['items'] as List<dynamic>? ?? const []) |
| 508 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 509 | .toList(); |
| 510 | } |
| 511 | |
| 512 | @override |
| 513 | Future<Map<String, dynamic>> getChildSupportSummary( |
| 514 | String familyId, |
| 515 | String studentUserId, |
| 516 | ) => |
| 517 | _json( |
| 518 | 'GET', |
| 519 | '/v1/families/$familyId/children/$studentUserId/support-summary', |
| 520 | auth: true, |
| 521 | ); |
| 522 | |
| 523 | @override |
| 524 | Future<Map<String, dynamic>> submitSyncMutations( |
| 525 | List<Map<String, dynamic>> mutations, |
| 526 | ) => |
| 527 | _json( |
| 528 | 'POST', |
| 529 | '/v1/sync/mutations', |
| 530 | auth: true, |
| 531 | body: {'mutations': mutations}, |
| 532 | ); |
| 533 | |
| 534 | @override |
| 535 | Future<Map<String, dynamic>> createLearningGoal({ |
| 536 | required String title, |
| 537 | String? target, |
| 538 | String? subjectId, |
| 539 | }) => |
| 540 | _json('POST', '/v1/learning/goals', auth: true, body: { |
| 541 | 'title': title, |
| 542 | if (target != null) 'target': target, |
| 543 | if (subjectId != null) 'subjectId': subjectId, |
| 544 | }); |
| 545 | |
| 546 | @override |
| 547 | Future<List<Map<String, dynamic>>> listLearningGoals() async { |
| 548 | final result = await _json('GET', '/v1/learning/goals', auth: true); |
| 549 | return (result['items'] as List<dynamic>? ?? const []) |
| 550 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 551 | .toList(); |
| 552 | } |
| 553 | |
| 554 | @override |
| 555 | Future<Map<String, dynamic>> createLearningCheckin({ |
| 556 | String? learningGoalId, |
| 557 | required int confidence, |
| 558 | required int difficulty, |
| 559 | String? note, |
| 560 | }) => |
| 561 | _json('POST', '/v1/learning/checkins', auth: true, body: { |
| 562 | if (learningGoalId != null) 'learningGoalId': learningGoalId, |
| 563 | 'confidence': confidence, |
| 564 | 'difficulty': difficulty, |
| 565 | if (note != null) 'note': note, |
| 566 | }); |
| 567 | |
| 568 | @override |
| 569 | Future<Map<String, dynamic>> createWellbeingCheckin({ |
| 570 | required int mood, |
| 571 | required int energy, |
| 572 | required int stress, |
| 573 | String? note, |
| 574 | String visibility = 'private', |
| 575 | }) => |
| 576 | _json('POST', '/v1/wellbeing/checkins', auth: true, body: { |
| 577 | 'mood': mood, |
| 578 | 'energy': energy, |
| 579 | 'stress': stress, |
| 580 | if (note != null) 'note': note, |
| 581 | 'visibility': visibility, |
| 582 | }); |
| 583 | |
| 584 | @override |
| 585 | Future<List<Map<String, dynamic>>> listWellbeingCheckins() async { |
| 586 | final result = await _json('GET', '/v1/wellbeing/checkins', auth: true); |
| 587 | return (result['items'] as List<dynamic>? ?? const []) |
| 588 | .map((item) => Map<String, dynamic>.from(item as Map)) |
| 589 | .toList(); |
| 590 | } |
| 591 | |
| 592 | @override |
| 593 | Future<Map<String, dynamic>> createAiSession(String kind) => |
| 594 | _json('POST', '/v1/ai/sessions', auth: true, body: {'kind': kind}); |
| 595 | |
| 596 | @override |
| 597 | Future<Map<String, dynamic>> sendAiMessage( |
| 598 | String sessionId, |
| 599 | String message, |
| 600 | ) => |
| 601 | _json( |
| 602 | 'POST', |
| 603 | '/v1/ai/sessions/$sessionId/messages', |
| 604 | auth: true, |
| 605 | body: {'message': message}, |
| 606 | ); |
| 607 | |
| 608 | @override |
| 609 | Future<Map<String, dynamic>> getGuardianWellbeingSummary( |
| 610 | String familyId, |
| 611 | String minorUserId, |
| 612 | ) => |
| 613 | _json( |
| 614 | 'GET', |
| 615 | '/v1/families/$familyId/children/$minorUserId/wellbeing-summary', |
| 616 | auth: true, |
| 617 | ); |
| 618 | |
| 619 | @override |
| 620 | Future<Map<String, dynamic>> requestFamilyGuidance( |
| 621 | String familyId, |
| 622 | String minorUserId, |
| 623 | String question, |
| 624 | ) => |
| 625 | _json( |
| 626 | 'POST', |
| 627 | '/v1/families/$familyId/children/$minorUserId/family-guidance', |
| 628 | auth: true, |
| 629 | body: {'question': question}, |
| 630 | ); |
| 631 | |
| 632 | } |