import { api } from "@/config/axios";
import { OrdersResponse } from "../types/Types";
import { OrderStatus } from "../enum/Enum";

export const getOrders = async (
  status: "old" | "current"
): Promise<OrdersResponse> => {
  const statuses =
    status === "old"
      ? [OrderStatus.COMPLETED, OrderStatus.CANCELED]
      : [
          OrderStatus.PENDING_PAYMENT,
          OrderStatus.PAID,
          OrderStatus.PREPARING,
          OrderStatus.DELIVERED_TO_WAITER,
          OrderStatus.DELIVERED_TO_RECEPTIONIST,
          OrderStatus.SHIPPED,
          OrderStatus.COMPLETED,
        ];

  const { data } = await api.get<OrdersResponse>(`/public/orders`, {
    params: {
      statuses: statuses,
    },
    paramsSerializer: {
      indexes: null,
    },
  });
  return data;
};
