import type {
  GetSupportAgency,
  GetSupportUser,
} from "@/pages/support/lib/types";
import httpClient from "@/shared/config/api/httpClient";
import {
  APPROVED_AGENCY,
  SUPPORT_AGENCY,
  SUPPORT_USER,
  TOUR_ADMIN,
} from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const getSupportUser = async (params: {
  page: number;
  page_size: number;
  status: "pending" | "done" | "failed" | "";
}): Promise<AxiosResponse<GetSupportUser>> => {
  const res = await httpClient.get(SUPPORT_USER, { params });
  return res;
};

const updateSupportUser = async ({
  body,
  id,
}: {
  id: number;
  body: {
    name: string;
    phone_number: string;
    travel_agency: number | null;
    status: "pending" | "done" | "failed";
  };
}) => {
  const res = await httpClient.patch(`${SUPPORT_USER}${id}/`, body);
  return res;
};

const deleteSupportUser = async ({ id }: { id: number }) => {
  const res = await httpClient.delete(`${SUPPORT_USER}${id}/`);
  return res;
};

//support for agency

const getSupportAgency = async (params: {
  page: number;
  page_size: number;
  search: string;
  status: "pending" | "approved" | "cancelled" | "";
}): Promise<AxiosResponse<GetSupportAgency>> => {
  const res = await httpClient.get(SUPPORT_AGENCY, { params });
  return res;
};

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

const createTourAdmin = async (
  id: number,
): Promise<
  AxiosResponse<{
    status: boolean;
    data: {
      id: number;
      phone: string;
      role: string;
      travel_agency: string;
      password: string;
    };
  }>
> => {
  const res = await httpClient.post(`${TOUR_ADMIN}${id}/create/`);
  return res;
};

const updateTour = async ({
  id,
  body,
}: {
  id: number;
  body: {
    status: "pending" | "approved" | "cancelled";
  };
}) => {
  const res = await httpClient.patch(`${APPROVED_AGENCY}${id}/`, body);
  return res;
};

export {
  createTourAdmin,
  deleteSupportUser,
  getSupportAgency,
  getSupportAgencyDetail,
  getSupportUser,
  updateSupportUser,
  updateTour,
};
