"use client";

import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { queryKeys } from "@/core/api";
import { useAuthSession } from "@/features/auth/stores/auth.store";
import { verificationService } from "../api/verification.api";

export function useResidenceCardVerification(options?: { enabled?: boolean }) {
  const { isAuthenticated } = useAuthSession();
  return useQuery({
    queryKey: queryKeys.verification.residenceCard(),
    queryFn: () => verificationService.getResidenceCardVerification(),
    enabled: (options?.enabled ?? true) && isAuthenticated,
  });
}

export function useSubmitResidenceCard() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: (file: File) => verificationService.submitResidenceCard(file),
    onSuccess: async () => {
      await queryClient.invalidateQueries({ queryKey: queryKeys.verification.residenceCard() });
    },
  });
}
