import { UpdateLanguageFormValues } from "@/components/forms/languages/update/UpdateLanguageForm";
import {
  createLanguage,
  deleteLanguage,
  getAllLanguages,
  updateLanguage,
} from "@/service/apis/languages";
import { ServerResponse } from "@/types";
import { useMutation, useQuery } from "@tanstack/react-query";

export const useGetLanguages = () =>
  useQuery({
    queryKey: ["get-all-languages"],
    queryFn: () => getAllLanguages(),
    retry: false,
    refetchOnWindowFocus: false,
  });

export const useCreateLanguage = () =>
  useMutation({ mutationFn: createLanguage });
export const useUpdateLanguage = () =>
  useMutation<
    ServerResponse,
    Error,
    { data: UpdateLanguageFormValues; id: string },
    ServerResponse
  >({ mutationFn: updateLanguage });
export const useDeleteLanguage = () =>
  useMutation({ mutationFn: deleteLanguage });
