import { friendsQueryKeys } from '../../friends/friends-query-keys';
import { friendsApi, type PostGetFriendsDataReturn } from '../../friends/friends-api';

import type { BaseAxiosError } from '../../../../types';

import { useMutation } from '@tanstack/react-query';

export const useGetFriendsMutation = () => {
  return useMutation<
    PostGetFriendsDataReturn,
    BaseAxiosError,
    { id: number; page: number; sort?: string; age?: number; country?: string },
    PostGetFriendsDataReturn
  >({
    mutationKey: friendsQueryKeys.getFriends(),
    mutationFn: async (variables) => {
      const response = await friendsApi.getFriends(
        variables.id,
        variables.page,
        variables.sort,
        variables.age,
        variables.country
      );
      return response.data;
    }
  });
};
