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

/**
 * The real go-live switch (`POST nurse_profiles/set_accepting_bookings`) — flips
 * `isAcceptingBookings` independently of verification. Invalidates the nurse profile so the
 * activation checklist / publish gate re-render the live state from the server, never an optimistic
 * "published" toast before the mutation actually succeeds.
 */
export function useSetAcceptingBookings() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: (accepting: boolean) => profilesApi.setAcceptingBookings(accepting),
    onSuccess: () => queryClient.invalidateQueries({ queryKey: profileKeys.nurse() }),
  });
}
