import { pikku } from "@/pikku/http"
import { useQuery } from "@tanstack/react-query"
import { CandidateResults } from "@heygermany/sdk"
import { useI18n } from "@/context/i18n-provider"

export const useGetCandidateResults = (candidateId?: string) => {
    const { locale } = useI18n()
    return useQuery({
        queryKey: ['candidate', candidateId, 'results', locale],
        queryFn: async (): Promise<CandidateResults> => {
            try {
                const result = await pikku().get(`/candidate/:candidateId/results`, { candidateId: candidateId!, locale })
                return result
            } catch (error) {
                throw error
            }
        },
        enabled: !!candidateId,
        retry: false // Disable retry for debugging
    })
}