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

/** Assign an alert to an owner (open → assigned). Invalidate the alert worklist on success. */
export function useAssignSupportAlert() {
  const queryClient = useQueryClient();
  return useMutation<void, unknown, { alertId: number; ownerUserId: number }>({
    mutationFn: ({ alertId, ownerUserId }) => adminApi.assignSupportAlert(alertId, ownerUserId),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: adminKeys.supportAlerts() });
    },
  });
}
