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

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

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

export const useGetMyFriendsMutation = () => {
  return useMutation<
    PostGetFriendsSettingsDataReturn,
    BaseAxiosError,
    { token: string; type: string; page: number; sort?: string; age?: number; country?: string },
    PostGetFriendsSettingsDataReturn
  >({
    mutationKey: friendsQueryKeys.loadFriendsSettings(),
    mutationFn: async (variables) => {
      const response = await friendsApi.loadFriendsSettings(
        variables.token,
        variables.type,
        variables.page,
        variables.sort,
        variables.age,
        variables.country
      );
      return response.data;
    }
  });
};
