import type {
  AllAmenitiesData,
  CreateTourRes,
  DetailAmenitiesData,
  GetAllTours,
  GetDetailTours,
  GetHotelRes,
  GetOneTours,
  Hotel_Badge,
  Hotel_BadgeId,
  Hotel_Tarif,
  Hotel_TarifId,
  Hotel_TranportId,
  Hotel_Transport,
  Hotel_Type,
  Hotel_TypeId,
  HotelAllFeatures,
  HotelAllFeaturesType,
  HotelFeaturesDetail,
  HotelFeaturesTypeDetail,
} from "@/pages/tours/lib/type";
import httpClient from "@/shared/config/api/httpClient";
import {
  AMENITIES,
  GET_TICKET,
  HOTEL,
  HOTEL_BADGE,
  HOTEL_FEATURES,
  HOTEL_FEATURES_TYPE,
  HOTEL_TARIF,
  HPTEL_TYPES,
  POPULAR_TOURS,
  TOUR_TRANSPORT,
} from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const getAllTours = async ({
  page,
  page_size,
  featured_tickets,
}: {
  page_size: number;
  page: number;
  featured_tickets?: boolean;
}): Promise<AxiosResponse<GetAllTours>> => {
  const response = await httpClient.get(GET_TICKET, {
    params: {
      page,
      page_size,
      featured_tickets,
    },
  });
  return response;
};

const getOneTours = async ({
  id,
}: {
  id: number;
}): Promise<AxiosResponse<GetOneTours>> => {
  const response = await httpClient.get(`${GET_TICKET}${id}`);
  return response;
};

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

const createTours = async ({
  body,
}: {
  body: FormData;
}): Promise<AxiosResponse<CreateTourRes>> => {
  const response = await httpClient.post(`${GET_TICKET}`, body, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return response;
};

const updateTours = async ({
  body,
  id,
}: {
  id: number;
  body: FormData;
}): Promise<AxiosResponse<CreateTourRes>> => {
  const response = await httpClient.patch(`${GET_TICKET}${id}/`, body, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return response;
};

const createHotel = async ({ body }: { body: FormData }) => {
  const response = await httpClient.post(`${HOTEL}`, body, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return response;
};

const getHotel = async (
  ticket: number,
): Promise<AxiosResponse<GetHotelRes>> => {
  const res = await httpClient.get(HOTEL, { params: { ticket } });
  return res;
};

const editHotel = async ({ body, id }: { id: number; body: FormData }) => {
  const response = await httpClient.patch(`${HOTEL}${id}/`, body, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return response;
};

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

//added popular tours
const addedPopularTours = async ({
  id,
  value,
}: {
  id: number;
  value: number;
}) => {
  const res = await httpClient.post(`${POPULAR_TOURS}${id}/${value}/`);
  return res;
};

// htoel_badge api
const hotelBadge = async ({
  page,
  page_size,
}: {
  page_size: number;
  page: number;
}): Promise<AxiosResponse<Hotel_Badge>> => {
  const response = await httpClient.get(HOTEL_BADGE, {
    params: { page, page_size },
  });
  return response;
};

const hotelBadgeCreate = async ({
  body,
}: {
  body: { name: string; color: string; name_ru: string };
}) => {
  const response = await httpClient.post(`${HOTEL_BADGE}`, body);
  return response;
};

const hotelBadgeUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { name: string; color: string; name_ru: string };
}) => {
  const response = await httpClient.patch(`${HOTEL_BADGE}${id}/`, body);
  return response;
};

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

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

// htoel_tarif api
const hotelTarif = async ({
  page,
  page_size,
}: {
  page_size: number;
  page: number;
}): Promise<AxiosResponse<Hotel_Tarif>> => {
  const response = await httpClient.get(HOTEL_TARIF, {
    params: { page, page_size },
  });
  return response;
};

const hotelTarifCreate = async ({
  body,
}: {
  body: {
    name: string;
    name_ru: string;
  };
}) => {
  const response = await httpClient.post(HOTEL_TARIF, body);
  return response;
};

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

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

const hoteltarifUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { name: string; name_ru: string };
}) => {
  const response = await httpClient.patch(`${HOTEL_TARIF}${id}/`, body);
  return response;
};

// htoel_tarnsport api
const hotelTransport = async ({
  page,
  page_size,
}: {
  page_size: number;
  page: number;
}): Promise<AxiosResponse<Hotel_Transport>> => {
  const response = await httpClient.get(TOUR_TRANSPORT, {
    params: { page, page_size },
  });
  return response;
};

const hotelTranportCreate = async ({
  body,
}: {
  body: {
    name: string;
    name_ru: string;
    icon_name: string;
  };
}) => {
  const response = await httpClient.post(TOUR_TRANSPORT, body);
  return response;
};

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

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

const hotelTransportUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { name: string; name_ru: string; icon_name: string };
}) => {
  const response = await httpClient.patch(`${TOUR_TRANSPORT}${id}/`, body);
  return response;
};

//hotel_type
const hotelType = async ({
  page,
  page_size,
}: {
  page_size: number;
  page: number;
}): Promise<AxiosResponse<Hotel_Type>> => {
  const response = await httpClient.get(HPTEL_TYPES, {
    params: { page, page_size },
  });
  return response;
};

const hotelTypeCreate = async ({
  body,
}: {
  body: {
    name: string;
    name_ru: string;
  };
}) => {
  const response = await httpClient.post(HPTEL_TYPES, body);
  return response;
};

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

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

const hotelTypeUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { name: string; name_ru: string };
}) => {
  const response = await httpClient.patch(`${HPTEL_TYPES}${id}/`, body);
  return response;
};

// hotel_features
const hotelFeature = async ({
  page,
  page_size,
}: {
  page_size: number;
  page: number;
}): Promise<AxiosResponse<HotelAllFeatures>> => {
  const response = await httpClient.get(HOTEL_FEATURES, {
    params: { page, page_size },
  });
  return response;
};

const hotelFeatureType = async ({
  page,
  page_size,
  feature_type,
}: {
  page_size: number;
  page: number;
  feature_type: number;
}): Promise<AxiosResponse<HotelAllFeaturesType>> => {
  const response = await httpClient.get(HOTEL_FEATURES_TYPE, {
    params: { page, page_size, feature_type },
  });
  return response;
};

const hotelFeatureCreate = async ({
  body,
}: {
  body: {
    hotel_feature_type_name: string;
    hotel_feature_type_name_ru: string;
  };
}) => {
  const response = await httpClient.post(`${HOTEL_FEATURES}`, body);
  return response;
};

const hotelFeatureTypeCreate = async ({
  body,
}: {
  body: {
    feature_name: string;
    feature_name_ru: string;
    feature_type: number;
  };
}) => {
  const response = await httpClient.post(`${HOTEL_FEATURES_TYPE}`, body);
  return response;
};

const hotelFeatureUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { hotel_feature_type_name: string; hotel_feature_type_name_ru: string };
}) => {
  const response = await httpClient.patch(`${HOTEL_FEATURES}${id}/`, body);
  return response;
};

const hotelFeatureTypeUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { feature_name: string; feature_name_ru: string };
}) => {
  const response = await httpClient.patch(`${HOTEL_FEATURES_TYPE}${id}/`, body);
  return response;
};

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

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

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

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

//Amenities

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

const amenitiesCreate = async ({
  body,
}: {
  body: {
    name: string;
    name_ru: string;
    icon_name: string;
  };
}) => {
  const response = await httpClient.post(AMENITIES, body);
  return response;
};

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

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

const amenitiesUpdate = async ({
  id,
  body,
}: {
  id: number;
  body: { name: string; name_ru: string; icon_name: string };
}) => {
  const response = await httpClient.patch(`${AMENITIES}${id}/`, body);
  return response;
};

export {
  addedPopularTours,
  amenitiesCreate,
  amenitiesUpdate,
  createHotel,
  createTours,
  deleteAmenities,
  deleteTours,
  editHotel,
  getAllAmenities,
  getAllTours,
  getDetailAmenities,
  getDetailToursId,
  getHotel,
  getOneTours,
  hotelBadge,
  hotelBadgeCreate,
  hotelBadgeDelete,
  hotelBadgeDetail,
  hotelBadgeUpdate,
  hotelFeature,
  hotelFeatureCreate,
  hotelFeatureDelete,
  hotelFeatureDetail,
  hotelFeatureType,
  hotelFeatureTypeCreate,
  hotelFeatureTypeDelete,
  hotelFeatureTypeDetail,
  hotelFeatureTypeUpdate,
  hotelFeatureUpdate,
  hotelTarfiDetail,
  hotelTarif,
  hotelTarifCreate,
  hotelTarifDelete,
  hoteltarifUpdate,
  hotelTranportCreate,
  hotelTransport,
  hotelTransportDelete,
  hotelTransportDetail,
  hotelTransportUpdate,
  hotelType,
  hotelTypeCreate,
  hotelTypeDelete,
  hotelTypeDetail,
  hotelTypeUpdate,
  updateTours,
};
