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

/**
 * Opens (or re-opens) verification and seeds the checklist — called from the B3 "start / continue" CTA
 * when the aggregate is `not_started`. Idempotent server-side. Writes the fresh status straight into
 * the cache so the checklist renders the seeded steps without a second fetch.
 */
export function useStartVerification() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: () => verificationApi.start(),
    onSuccess: (status) => {
      queryClient.setQueryData(verificationKeys.status(), status);
    },
  });
}
