import 'package:dio/dio.dart'; import '../../../core/api/api_client.dart'; import '../../../core/storage/token_store.dart'; class AppUser { final String id; final String phone; final String? name; final String role; AppUser({required this.id, required this.phone, this.name, required this.role}); factory AppUser.fromJson(Map j) => AppUser( id: j['id'] as String, phone: (j['phone'] ?? '') as String, name: j['name'] as String?, role: (j['role'] ?? 'driver') as String, ); } class AuthRepository { final ApiClient _api; final TokenStore _store; AuthRepository(this._api, this._store); Future sendOtp(String phone) async { await _api.dio.post('/auth/send-otp', data: {'phone': phone}); } Future verify(String phone, String code) async { final r = await _api.dio.post( '/auth/verify-otp', data: {'phone': phone, 'code': code}, ); await _store.save( r.data['access_token'] as String, r.data['refresh_token'] as String, ); return AppUser.fromJson(Map.from(r.data['user'] as Map)); } Future me() async { try { final r = await _api.dio.get('/users/me'); return AppUser.fromJson(Map.from(r.data as Map)); } on DioException { return null; } } Future logout() => _store.clear(); }