import { useMutation, useQuery } from "@tanstack/react-query";
import {
  getCompanies,
  getIdWithSlug,
  getIndustry,
  getCompanyDetail,
  getCompanyRequest,
  getMyCompany,
} from "../service/HomeService";

export const useGetSlugId = () => {
  return useMutation({
    mutationFn: (slug: string) => getIdWithSlug(slug),
  });
};

export const useGetIndustry = () => {
  return useQuery({
    queryKey: ["industry"],
    queryFn: () => getIndustry(),
  });
};

export const useGetCompanies = (industryId: string) => {
  return useQuery({
    queryKey: ["companies", industryId],
    queryFn: () => getCompanies(industryId),
  });
};

export const useGetCompanyDetail = (id: string) => {
  return useQuery({
    queryKey: ["company", id],
    queryFn: () => getCompanyDetail(id),
    enabled: !!id,
  });
};

export const useGetCompanyRequest = () => {
  return useQuery({
    queryKey: ["company-request"],
    queryFn: () => getCompanyRequest(),
    enabled: !!localStorage.getItem(import.meta.env.VITE_TOKEN_NAME),
  });
};

export const useGetMyCompany = () => {
  return useQuery({
    queryKey: ["my-company"],
    queryFn: () => getMyCompany(),
  });
};
