import * as api from "../service/Service";
import { useMutation, useQuery } from "@tanstack/react-query";
import { CreateCompanyType } from "../types/Types";

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

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

export const useGetCompanyById = (id: string | undefined) => {
  return useQuery({
    queryKey: ["company", id],
    queryFn: () => (id ? api.getCompanyById(id) : null),
    enabled: !!id,
  });
};

export const useSingleUpload = () => {
  return useMutation({
    mutationFn: (variables: FormData) => api.uploadSingle(variables),
  });
};
export const useMultiUpload = () => {
  return useMutation({
    mutationFn: (variables: FormData) => api.uploadMultiple(variables),
  });
};

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