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

import { mapsQueryKeys } from '../maps-query-keys';
import { mapsApi, type PostGetMapDataForRegion } from '../maps-api';

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

export const usePostGetMapDataForRegionMutation = () => {
  return useMutation<
    PostGetMapDataForRegion,
    BaseAxiosError,
    { token: string; region_id: number },
    PostGetMapDataForRegion
  >({
    mutationKey: mapsQueryKeys.getMapDataForRegion(),
    mutationFn: async (data) => {
      const response = await mapsApi.getMapDataForRegion(data.token, data.region_id);
      return response.data;
    }
  });
};
