import axios from "@/config/axios";
import {
  AddCartType,
  UpdateCartType,
  RemoveCartType,
  CartResponseType,
  ShippingCostResponseType,
  PaymentMethodsResponseType,
  CheckoutCartType,
  CheckoutResponseType,
  ApplyDiscountType,
  ApplyDiscountResponseType,
  PaymentStatusType,
  PaymentStatusResponseType,
  BulkAddCartType,
  ShipmentCartResponseType,
  ShipmentSaveType,
} from "../types/Types";

export const getCart = async (): Promise<CartResponseType> => {
  const { data } = await axios.get("/cart");
  return data;
};

export const addToCart = async (params: AddCartType) => {
  const { data } = await axios.post("/cart/add", params);
  return data;
};

export const updateCart = async (params: UpdateCartType) => {
  const { data } = await axios.post("/cart/update", params);
  return data;
};

export const removeFromCart = async (params: RemoveCartType) => {
  const { data } = await axios.post("/cart/remove", params);
  return data;
};

export const shippingCost = async (): Promise<ShippingCostResponseType> => {
  const { data } = await axios.get("/shipment/shipping-cost");
  return data;
};

export const paymentMethods = async (): Promise<PaymentMethodsResponseType> => {
  const { data } = await axios.get("/payment/methods");
  return data;
};

export const checkoutCart = async (
  params: CheckoutCartType
): Promise<CheckoutResponseType> => {
  const { data } = await axios.post("/payment/checkout/cart", params);
  return data;
};

export const applyDiscountCode = async (
  params: ApplyDiscountType
): Promise<ApplyDiscountResponseType> => {
  const { data } = await axios.post("/cart/apply-discount", params);
  return data;
};

export const checkPaymentStatus = async (
  params: PaymentStatusType
): Promise<PaymentStatusResponseType> => {
  const { data } = await axios.post("/payment/verify", params);
  return data;
};

export const removeAllCart = async () => {
  const { data } = await axios.post("/cart/clear");
  return data;
};

export const bulkAddCart = async (params: BulkAddCartType) => {
  const { data } = await axios.post("/cart/bulk-add", params);
  return data;
};

export const getShipmentCart = async (): Promise<ShipmentCartResponseType> => {
  const { data } = await axios.get<ShipmentCartResponseType>("/shipment/cart");
  return data;
};

export const saveShipmentCart = async (params: ShipmentSaveType) => {
  const { data } = await axios.post("/shipment/save", params);
  return data;
};
