import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/DiscountService";
import { CreateDiscountType } from "../types/DiscountTypes";

export const useCreateDiscount = () => {
  return useMutation({
    mutationFn: (variables: CreateDiscountType) =>
      api.createDiscount(variables),
  });
};

export const useGetDiscounts = (search: string) => {
  return useQuery({
    queryKey: ["discounts", search],
    queryFn: () => api.getDiscounts(search),
  });
};

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

export const useGetDiscountDetail = (id: string) => {
  return useQuery({
    queryKey: ["discount", id],
    queryFn: () => api.getDiscountDetail(id),
  });
};

export const useUpdateDiscount = () => {
  return useMutation({
    mutationFn: (variables: { id: string; params: CreateDiscountType }) =>
      api.updateDiscount(variables.id, variables.params),
  });
};

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