import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/AdsService";
import { CreateAdsType } from "../types/AdsTypes";

export const useGetAdsList = (
  page: number,
  search: string,
  isActive: boolean,
  since: string
) => {
  return useQuery({
    queryKey: ["ads", page, search, isActive, since],
    queryFn: () => api.getAdsList({ page, search, isActive, since }),
  });
};

export const useCreateAds = () => {
  return useMutation({
    mutationFn: (variables: CreateAdsType) => api.createAds(variables),
  });
};

export const useToggleStatusAds = () => {
  return useMutation({
    mutationFn: (variables: string) => api.toggleStatusAds(variables),
  });
};

export const useGetDetailAds = (id?: string) => {
  return useQuery({
    queryKey: ["ads-detail", id],
    queryFn: () => api.getDetailAds(id ? id : ""),
    enabled: !!id,
  });
};

export const useUpdateAds = (id: string) => {
  return useMutation({
    mutationFn: (variables: CreateAdsType) => api.updateAds(id, variables),
  });
};

export const useDeleteAds = () => {
  return useMutation({
    mutationFn: (variables: string) => api.deleteAds(variables),
  });
};
