import type {
  AgencyOrderData,
  UserAgencyDetailData,
  UserOrderData,
  UserOrderDetailData,
} from "@/pages/finance/lib/type";
import httpClient from "@/shared/config/api/httpClient";
import { AGENCY_ORDERS, USER_ORDERS } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const getAllOrder = async (params: {
  page: number;
  page_size: number;
  order_status:
    | "pending_payment"
    | "pending_confirmation"
    | "cancelled"
    | "confirmed"
    | "completed"
    | "";
}): Promise<AxiosResponse<UserOrderData>> => {
  const res = await httpClient.get(USER_ORDERS, { params });
  return res;
};

const getAllOrderAgecy = async (params: {
  page: number;
  page_size: number;
}): Promise<AxiosResponse<AgencyOrderData>> => {
  const res = await httpClient.get(AGENCY_ORDERS, { params });
  return res;
};

const getDetailOrder = async (
  id: number,
): Promise<AxiosResponse<UserOrderDetailData>> => {
  const res = await httpClient.get(`${USER_ORDERS}${id}/`);
  return res;
};

const getDetailAgencyOrder = async (
  id: number,
): Promise<AxiosResponse<UserAgencyDetailData>> => {
  const res = await httpClient.get(`${AGENCY_ORDERS}${id}/`);
  return res;
};

const updateDetailOrder = async ({
  id,
  body,
}: {
  id: number;
  body: {
    order_status:
      | "pending_payment"
      | "pending_confirmation"
      | "cancelled"
      | "confirmed"
      | "completed";
  };
}) => {
  const res = await httpClient.patch(`${USER_ORDERS}${id}/`, body);
  return res;
};

export {
  getAllOrder,
  getAllOrderAgecy,
  getDetailAgencyOrder,
  getDetailOrder,
  updateDetailOrder,
};
