#pragma once #include "partners_api/booking_availability_params.hpp" #include "partners_api/booking_block_params.hpp" #include "platform/safe_callback.hpp" #include #include #include #include #include #include namespace booking { struct HotelPhotoUrls { std::string m_small; std::string m_original; }; struct HotelReview { /// An issue date. std::chrono::time_point m_date; /// Author's hotel evaluation. float m_score = 0.0; /// Review author name. std::string m_author; /// Review text. There can be either one or both positive/negative review. std::string m_pros; std::string m_cons; }; struct HotelFacility { std::string m_type; std::string m_name; }; struct HotelInfo { std::string m_hotelId; std::string m_description; std::vector m_photos; std::vector m_facilities; std::vector m_reviews; float m_score = 0.0; uint32_t m_scoreCount = 0; }; struct Deals { enum class Type { /// Good price. Smart, /// Sale with discount in percent from base price. LastMinute }; std::vector m_types; uint8_t m_discount = 0; }; struct BlockInfo { static double constexpr kIncorrectPrice = std::numeric_limits::max(); std::string m_blockId; std::string m_name; std::string m_description; uint8_t m_maxOccupancy = 0; double m_minPrice = kIncorrectPrice; std::string m_currency; std::vector m_photos; Deals m_deals; std::chrono::time_point m_refundableUntil; bool m_breakfastIncluded = false; bool m_depositRequired = false; }; struct Blocks { void Add(BlockInfo && block) { if (block.m_minPrice < m_totalMinPrice) { m_totalMinPrice = block.m_minPrice; m_currency = block.m_currency; } if (!m_hasSmartDeal) { auto const & types = block.m_deals.m_types; m_hasSmartDeal = std::find(types.cbegin(), types.cend(), Deals::Type::Smart) != types.cend(); } if (block.m_deals.m_discount > m_maxDiscount) m_maxDiscount = block.m_deals.m_discount; m_blocks.emplace_back(block); } double m_totalMinPrice = BlockInfo::kIncorrectPrice; std::string m_currency; uint8_t m_maxDiscount = 0; bool m_hasSmartDeal = false; std::vector m_blocks; }; struct Extras { Extras() = default; Extras(double price, std::string const & currency) : m_price(price), m_currency(currency) {} double m_price = 0.0; std::string m_currency; }; using HotelsWithExtras = std::unordered_map; class RawApi { public: static bool GetExtendedInfo(std::string const & hotelId, std::string const & lang, std::string & result); // Booking Api v2 methods: static bool HotelAvailability(AvailabilityParams const & params, std::string & result); static bool BlockAvailability(BlockParams const & params, std::string & result); static size_t constexpr GetMaxHotelsInAvailabilityRequest() { return 300; }; }; using BlockAvailabilityCallback = platform::SafeCallback; using GetHotelInfoCallback = platform::SafeCallback; // NOTE: this callback will be called on the network thread. using GetHotelAvailabilityCallback = std::function; /// Callbacks will be called in the same order as methods are called. class Api { public: Api(); std::string GetBookHotelUrl(std::string const & baseUrl) const; std::string GetDeepLink(std::string const & hotelId) const; std::string GetDescriptionUrl(std::string const & baseUrl) const; std::string GetMoreUrl(std::string const & baseUrl) const; std::string GetHotelReviewsUrl(std::string const & hotelId, std::string const & baseUrl) const; std::string GetSearchUrl(std::string const & city, std::string const & name) const; std::string ApplyAvailabilityParams(std::string const & url, AvailabilityParams const & params) const; /// Real-time information methods (used for retrieving rapidly changing information). /// These methods send requests directly to Booking. void GetBlockAvailability(BlockParams && params, BlockAvailabilityCallback const & fn) const; /// NOTE: callback will be called on the network thread. void GetHotelAvailability(AvailabilityParams const & params, GetHotelAvailabilityCallback const & fn) const; /// Static information methods (use for information that can be cached). /// These methods use caching server to prevent Booking from being ddossed. void GetHotelInfo(std::string const & hotelId, std::string const & lang, GetHotelInfoCallback const & fn) const; void SetAffiliateId(std::string const & affiliateId); private: std::string m_affiliateId; }; void SetBookingUrlForTesting(std::string const & url); } // namespace booking