import axios from "@/config/axios";
import {
  OrdersResponse,
  OrderDetailResponse,
  CancelOrderType,
  CancelReasonsResponse,
  ReturnOrderType,
  ReturnReasonsResponse,
  ReturnOrdersResponse,
} from "../types/Types";

export const getOrders = async (activeTab: string): Promise<OrdersResponse> => {
  const { data } = await axios.get(`/user/profile/orders?status=${activeTab}`);
  return data;
};

export const getOrderDetail = async (
  orderId: string
): Promise<OrderDetailResponse> => {
  const { data } = await axios.get(`/order/${orderId}/user`);
  return data;
};

export const getInvoice = async (orderId: string) => {
  const { data } = await axios.get(`/order/${orderId}/invoice`, {
    responseType: "blob",
  });
  return data;
};

export const getCancelReasons = async (): Promise<CancelReasonsResponse> => {
  const { data } = await axios.get(`/cancel/reasons`);
  return data;
};

export const cancelOrder = async (params: CancelOrderType) => {
  const { data } = await axios.post(`/cancel/user`, params);
  return data;
};

export const getReturnReasons = async (): Promise<ReturnReasonsResponse> => {
  const { data } = await axios.get(`/returns/reasons`);
  return data;
};

export const returnOrder = async (params: ReturnOrderType) => {
  const { data } = await axios.post(`/returns/user`, params);
  return data;
};

export const getReturnOrder = async (): Promise<ReturnOrdersResponse> => {
  const { data } = await axios.get(`/returns/user`);
  return data;
};
