import axios from "@/config/axios";
import type {
  CreateCouponType,
  IGetCouponsResponse,
  IGetCouponDetailsResponse,
} from "../types/Types";

export const getCoupons = async (): Promise<IGetCouponsResponse> => {
  const { data } = await axios.get<IGetCouponsResponse>("/admin/coupons");
  return data;
};

export const createCoupon = async (params: CreateCouponType) => {
  const { data } = await axios.post("/admin/coupons", params);
  return data;
};

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

export const generateCouponCode = async () => {
  const { data } = await axios.get(`/admin/coupons/generate-code`);
  return data;
};

export const getCouponDetails = async (
  id: string
): Promise<IGetCouponDetailsResponse> => {
  const { data } = await axios.get<IGetCouponDetailsResponse>(
    `/admin/coupons/${id}`
  );
  return data;
};

export const updateCoupon = async (id: string, params: CreateCouponType) => {
  const { data } = await axios.patch(`/admin/coupons/${id}`, params);
  return data;
};
