import axios from "../../../config/axios";
import type {
  CreateCouponType,
  CouponType,
  CouponsResponse,
  GetCouponDetailResponseType,
} from "../types/Types";

export const getCoupons = async (
  page: number = 1
): Promise<CouponsResponse> => {
  const { data } = await axios.get(`/admin/coupon/native?page=${page}`);
  return data;
};

export const createCoupon = async (
  couponData: CreateCouponType
): Promise<CouponType> => {
  const { data } = await axios.post("/admin/coupon", couponData);
  return data;
};

export const deleteCoupon = async (couponId: string): Promise<void> => {
  await axios.delete(`/admin/coupon/${couponId}`);
};

export const getCouponDetail = async (
  couponId: string
): Promise<GetCouponDetailResponseType> => {
  const { data } = await axios.get(`/admin/coupon/${couponId}`);
  return data;
};

export const updateCoupon = async (
  params: CreateCouponType
): Promise<CouponType> => {
  const { data } = await axios.patch(
    `/admin/coupon/${params.couponId}`,
    params
  );
  return data;
};
