import 'package:social_app/core/api/i_api_client.dart'; class FriendsApi { final IApiClient _client; static const _prefix = '/api/v1/friends'; FriendsApi(this._client); Future> getFriends() async { final response = await _client.get(_prefix); final List data = response.data; return data.map((json) => FriendResponse.fromJson(json)).toList(); } Future> getIncomingRequests() async { final response = await _client.get('$_prefix/requests/inbox'); final List data = response.data; return data.map((json) => FriendResponse.fromJson(json)).toList(); } Future> getOutgoingRequests() async { final response = await _client.get('$_prefix/requests/outgoing'); final List data = response.data; return data.map((json) => FriendResponse.fromJson(json)).toList(); } Future sendRequest(String targetUserId) async { final response = await _client.post( '$_prefix/requests', data: {'target_user_id': targetUserId}, ); return FriendResponse.fromJson(response.data); } Future acceptRequest(String friendshipId) async { final response = await _client.post( '$_prefix/requests/$friendshipId/accept', ); return FriendResponse.fromJson(response.data); } Future declineRequest(String friendshipId) async { final response = await _client.post( '$_prefix/requests/$friendshipId/decline', ); return FriendResponse.fromJson(response.data); } Future removeFriend(String friendshipId) async { await _client.delete('$_prefix/$friendshipId'); } } class FriendResponse { final String id; final UserBasicInfo friend; final String status; final DateTime createdAt; final DateTime? acceptedAt; FriendResponse({ required this.id, required this.friend, required this.status, required this.createdAt, this.acceptedAt, }); factory FriendResponse.fromJson(Map json) { return FriendResponse( id: json['id'] as String, friend: UserBasicInfo.fromJson(json['friend'] as Map), status: json['status'] as String, createdAt: DateTime.parse(json['created_at'] as String), acceptedAt: json['accepted_at'] != null ? DateTime.parse(json['accepted_at'] as String) : null, ); } } class UserBasicInfo { final String id; final String username; final String? avatarUrl; UserBasicInfo({required this.id, required this.username, this.avatarUrl}); factory UserBasicInfo.fromJson(Map json) { return UserBasicInfo( id: json['id'] as String, username: json['username'] as String, avatarUrl: json['avatar_url'] as String?, ); } }