import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/ServiceService";
import { BuyServiceType, CreateReviewType } from "../types/ServiecTypes";

export const useGetSuggestedServices = () => {
  return useQuery({
    queryKey: ["suggested-services"],
    queryFn: () => api.getServiceSuggestedDanak(),
  });
};

export const useGetCategoriesPublic = () => {
  return useQuery({
    queryKey: ["categories-public"],
    queryFn: () => api.getCategoriesPublic(),
  });
};

export const useGetServicesByCategory = (categoryId: string) => {
  return useQuery({
    queryKey: ["services-category", categoryId],
    queryFn: () => api.getServicesByCategory(categoryId),
  });
};

export const useGetDetailService = (serviceId: string) => {
  return useQuery({
    queryKey: ["service", serviceId],
    queryFn: () => api.getDetailService(serviceId),
    enabled: !!serviceId,
  });
};

export const useBuyService = () => {
  return useMutation({
    mutationFn: (variables: BuyServiceType) => api.buyService(variables),
  });
};

export const useGetMyServices = (search: string) => {
  return useQuery({
    queryKey: ["myservices", search],
    queryFn: () => api.getMyServices(search),
  });
};

export const useCreateReview = () => {
  return useMutation({
    mutationFn: (variables: CreateReviewType) => api.createReview(variables),
  });
};

export const useGetServiceBySlug = (slug: string) => {
  return useQuery({
    queryKey: ["service-by-slug", slug],
    queryFn: () => api.getServiceBySlug(slug),
  });
};
