import type {
  agencyUserData,
  GetAllAgencyData,
  GetDetailAgencyData,
} from "@/pages/agencies/lib/type";
import httpClient from "@/shared/config/api/httpClient";
import { GET_ALL_AGENCY, TOUR_ADMIN } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const getAllAgency = async ({
  page,
  page_size,
}: {
  page: number;
  page_size: number;
}): Promise<AxiosResponse<GetAllAgencyData>> => {
  const response = await httpClient.get(GET_ALL_AGENCY, {
    params: { page, page_size },
  });
  return response;
};

const getDetailAgency = async ({
  id,
}: {
  id: number;
}): Promise<AxiosResponse<GetDetailAgencyData>> => {
  const response = await httpClient.get(`${GET_ALL_AGENCY}${id}/`);
  return response;
};

const deleteAgency = async ({ id }: { id: number }) => {
  const response = await httpClient.delete(`${GET_ALL_AGENCY}${id}/`);
  return response;
};

const updateAgencyStatus = async ({
  id,
  body,
}: {
  id: number;
  body: {
    status: "pending" | "approved" | "cancelled";
    custom_id?: string;
    share_percentage?: number;
    name?: string;
    addres?: string;
    email?: string;
    phone?: string;
    web_site?: string;
    ticket_sold_count?: number;
    total_income?: number;
  };
}) => {
  const response = await httpClient.patch(`${GET_ALL_AGENCY}${id}/`, body);
  return response;
};

const agencyUser = async (
  id: number,
): Promise<AxiosResponse<agencyUserData>> => {
  const res = await httpClient.get(`${TOUR_ADMIN}${id}/list/`);
  return res;
};

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

const agencyUserUpdate = 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}/update/`);
  return res;
};

export {
  agencyUser,
  agencyUserDelete,
  agencyUserUpdate,
  deleteAgency,
  getAllAgency,
  getDetailAgency,
  updateAgencyStatus,
};
