import { useMutation, useQueryClient } from '@tanstack/react-query';
import { serviceAreasApi } from '../apis';
import { serviceAreaKeys } from '../keys';

/** Removes an owned coverage area, then invalidates the list. */
export function useRemoveServiceArea() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: (id: number) => serviceAreasApi.remove(id),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: serviceAreaKeys.lists() });
    },
  });
}
