import axios from "../../../config/axios";
import { CreateDiscountType } from "../types/DiscountTypes";

export const createDiscount = async (params: CreateDiscountType) => {
  const { data } = await axios.post(`/discounts`, params);
  return data;
};

export const getDiscounts = async (search: string) => {
  const { data } = await axios.get(`/discounts?q=${search}`);
  return data;
};

export const toggleStatusDiscount = async (id: string) => {
  const { data } = await axios.post(`/discounts/${id}/toggle-status`);
  return data;
};

export const getDiscountDetail = async (id: string) => {
  const { data } = await axios.get(`/discounts/${id}`);
  return data;
};

export const updateDiscount = async (
  id: string,
  params: CreateDiscountType
) => {
  const { data } = await axios.patch(`/discounts/${id}`, params);
  return data;
};

export const deleteDiscount = async (id: string) => {
  const { data } = await axios.delete(`/discounts/${id}`);
  return data;
};
