import '../../../core/api/api_client.dart'; import 'models/driver_profile_model.dart'; /// مستودع بيانات السائق — يُستخدم من DriverCubit. class DriverRepository { final ApiClient _api; DriverRepository(this._api); /// `GET /drivers/me` — جلب ملف السائق. Future getProfile() async { try { final r = await _api.dio.get('/drivers/me'); return DriverProfileModel.fromJson(r.data as Map); } catch (_) { return null; } } /// `PATCH /drivers/status` — تبديل الحالة (مُتصل/مُنقطع). Future setOnline(bool online) async { try { final r = await _api.dio.patch('/drivers/status', data: {'online': online}); return r.data['online'] as bool? ?? online; } catch (_) { return false; } } /// `POST /drivers/location` — إرسال الموقع الحالي. /// /// يُعيد `true` إذا كان الموقع "مُهماً" (تغيير كبير حسب السيرفر). Future sendLocation({ required double lat, required double lng, double? heading, double? speed, }) async { try { final r = await _api.dio.post('/drivers/location', data: { 'lat': lat, 'lng': lng, if (heading != null) 'heading': heading, if (speed != null) 'speed': speed, }); return r.data['significant'] as bool? ?? false; } catch (_) { return false; } } }