import { httpClient } from '../../../core/infrastructure/httpClient';
import type { FriendshipStatus, FriendRequest, FriendWithId } from '../../../core/domain/types';

export class FriendApi {
  static async getFriends() {
    return httpClient.request<FriendWithId[]>('/contacts');
  }

  static async getFriendRequests() {
    return httpClient.request<FriendRequest[]>('/contacts/requests');
  }

  static async getFriendshipStatus(userId: string) {
    return httpClient.request<FriendshipStatus>(`/contacts/status/${userId}`);
  }

  static async sendFriendRequest(friendId: string) {
    return httpClient.request<{ status: string }>('/contacts/request', {
      method: 'POST',
      body: JSON.stringify({ contactId: friendId }),
    });
  }

  static async acceptFriendRequest(friendshipId: string) {
    return httpClient.request<{ id: string }>(`/contacts/${friendshipId}/accept`, { method: 'POST' });
  }

  static async declineFriendRequest(friendshipId: string) {
    return httpClient.request<{ success: boolean }>(`/contacts/${friendshipId}/decline`, { method: 'POST' });
  }

  static async removeFriend(friendshipId: string) {
    return httpClient.request<{ success: boolean }>(`/contacts/${friendshipId}`, { method: 'DELETE' });
  }
}
