import { useMutation, useQuery } from "@tanstack/react-query";
import { CreateAnnouncementType } from "../../types/AnnouncementTypes";
import * as api from "../service/AnnoncementService";

export const useCreateAnnoncement = () => {
  return useMutation({
    mutationFn: (variables: CreateAnnouncementType) =>
      api.createAnnoncement(variables),
  });
};

export const useGetAnnoncements = (
  page: number,
  search: string,
  since: string
) => {
  return useQuery({
    queryKey: ["announcements", page, search, since],
    queryFn: () => api.getAnnoncements(page, search, since),
  });
};

export const useGetAnnoncementDetail = (id: string) => {
  return useQuery({
    queryKey: ["announcement", id],
    queryFn: () => api.getAnnoncementDetail(id),
    enabled: !!id,
  });
};

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

export const useUpdateAnnoncement = (id: string) => {
  return useMutation({
    mutationFn: (variables: CreateAnnouncementType) =>
      api.updateAnnoncement(id, variables),
  });
};

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