import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/CompanyService";
import { CreateIndustryType, CreateCompanyType } from "../types/CompanyTypes";
export const useGetIndustries = (
  page: number,
  search: string,
  isActive: string
) => {
  return useQuery({
    queryKey: ["industries", page, search, isActive],
    queryFn: () => api.getIndustries(page, search, isActive),
  });
};

export const useCreateIndustry = () => {
  return useMutation({
    mutationFn: api.createIndustry,
  });
};

export const useDeleteIndustry = () => {
  return useMutation({
    mutationFn: api.deleteIndustry,
  });
};

export const useChangeStatusIndustry = () => {
  return useMutation({
    mutationFn: (id: string) => api.changeStatusIndustry(id),
  });
};

export const useUpdateIndustry = () => {
  return useMutation({
    mutationFn: ({ id, params }: { id: string; params: CreateIndustryType }) =>
      api.updateIndustry(id, params),
  });
};

export const useGetIndustryDetail = (id: string) => {
  return useQuery({
    queryKey: ["industry-detail", id],
    queryFn: () => api.getIndustryDetail(id),
  });
};

export const useCreateCompany = () => {
  return useMutation({
    mutationFn: (params: CreateCompanyType) => api.createCompany(params),
  });
};

export const useGetCompanies = (page: number) => {
  return useQuery({
    queryKey: ["companies", page],
    queryFn: () => api.getCompanies(page),
  });
};

export const useDeleteCompany = () => {
  return useMutation({
    mutationFn: (id: string) => api.deleteCompany(id),
  });
};

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

export const useUpdateCompany = () => {
  return useMutation({
    mutationFn: ({ id, params }: { id: string; params: CreateCompanyType }) =>
      api.updateCompany(id, params),
  });
};

export const useToggleStatusCompany = () => {
  return useMutation({
    mutationFn: (id: string) => api.toggleStatusCompany(id),
  });
};
