import { pikku } from "@/pikku/http"
import type { DB } from '@heygermany/sdk'
import { useMutation, useQueryClient } from "@tanstack/react-query"

type ExperienceUpdatePayload = Partial<Omit<DB.CandidateExperience, 'candidateId' | 'experienceId' | 'createdAt' | 'lastUpdatedAt'>>

export const useUpdateCandidateExperience = (candidateId: string) => {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: async (data: ExperienceUpdatePayload) =>
      await pikku().patch("/backoffice/candidate/:candidateId/experience", { candidateId, ...data }),
    onSuccess: () => {
      queryClient.invalidateQueries({
        queryKey: ['backoffice', 'candidate', candidateId]
      })
    }
  })
}
