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 usePostUpdateLocationMutation = () => {
  return useMutation<
    ResponseType,
    BaseAxiosError,
    { token: string; lat: number; lng: number },
    ResponseType
  >({
    mutationKey: locationQueryKeys.updateLocation(),
    mutationFn: async (variables) => {
      const response = await locationApi.updateLocation(
        variables.token,
        variables.lat,
        variables.lng
      );
      return response.data;
    }
  });
};
