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

import { locationQueryKeys } from '../location-query-keys';
import { locationApi } from '../location-api';

import type { BaseAxiosError } from '../../../../types';
import { ResponseType } from '@api/response-type';

export const usePostGetUsersLocationFilteredMutation = () => {
  return useMutation<
    ResponseType,
    BaseAxiosError,
    { token: string; friends: 0 | 1; trusted: 0 | 1; countries?: string },
    ResponseType
  >({
    mutationKey: locationQueryKeys.getLocationFiltered(),
    mutationFn: async (variables) => {
      const response = await locationApi.getLocationFiltered(
        variables.token,
        variables.friends,
        variables.trusted,
        variables.countries
      );
      return response.data;
    }
  });
};
