import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:sighej/models/match_result.dart'; const _baseUrl = String.fromEnvironment('API_URL', defaultValue: 'http://10.0.2.2:8000'); /// Registers the user's profile with the backend session store. Future registerSession( String bleToken, List interests, { String name = '', String tagline = '', }) async { final response = await http.post( Uri.parse('$_baseUrl/session'), headers: {'Content-Type': 'application/json'}, body: jsonEncode({ 'ble_token': bleToken, 'interests': interests, if (name.isNotEmpty) 'name': name, if (tagline.isNotEmpty) 'tagline': tagline, }), ); if (response.statusCode != 200) { throw Exception('Failed to register session: ${response.statusCode}'); } } /// Reports a detected BLE token to the backend and returns the match result. /// Returns null if the backend returns a non-200 status (soft failure). Future reportMatch(String ownToken, String detectedToken) async { try { final response = await http.post( Uri.parse('$_baseUrl/match'), headers: {'Content-Type': 'application/json'}, body: jsonEncode({'own_token': ownToken, 'detected_token': detectedToken}), ); if (response.statusCode != 200) return null; return MatchResult.fromJson(jsonDecode(response.body) as Map); } catch (_) { return null; } }