#pragma once // Retail API (v2) and Recommendations AI (recommendationengine v1beta1, the // original product; Retail's predict is its successor). Predict, search, // products, catalogs, user events. Other rows through caller(). #include #include #include "google/enterprise/caller.h" namespace molo::google::enterprise { struct RetailNames { std::string project; std::string location = "global"; std::string catalog = "default_catalog"; std::string catalog_name() const; // projects/p/locations/l/catalogs/c std::string placement(const std::string& id) const; // .../placements/{id} std::string serving_config(const std::string& id) const; std::string branch(const std::string& id = "0") const; // .../branches/{id} }; struct RetailSearch { std::string placement; // placement or serving config full name std::string query; std::string visitor_id; // required by Retail std::string filter; std::string branch; int page_size = 10; int offset = 0; clients::body::Json extra = clients::body::Json::object(); clients::body::Json to_body() const; }; class Retail { public: Retail(std::shared_ptr client, Sleeper sleeper = nullptr); Caller& caller() { return caller_; } const Caller& caller() const { return caller_; } static Invocation search_invocation(const RetailSearch& s); static Invocation predict_invocation(const std::string& placement, const clients::body::Json& user_event, int page_size, bool validate_only); clients::body::Json search(const RetailSearch& s) const; // user_event: {eventType, visitorId, productDetails?...}; Retail requires it. clients::body::Json predict(const std::string& placement, const clients::body::Json& user_event, int page_size = 10, bool validate_only = false) const; clients::body::Json write_user_event(const std::string& catalog, const clients::body::Json& event) const; ListResult list_catalogs(const std::string& location_parent) const; ListResult list_products(const std::string& branch) const; clients::body::Json get_product(const std::string& name) const; ListResult list_serving_configs(const std::string& catalog) const; clients::body::Json delete_product(const std::string& name, bool confirm) const; private: Caller caller_; }; // Recommendations AI (legacy surface). class Recommendations { public: explicit Recommendations(std::shared_ptr client); Caller& caller() { return caller_; } const Caller& caller() const { return caller_; } static std::string placement(const std::string& project, const std::string& location, const std::string& catalog, const std::string& event_store, const std::string& placement_id); static Invocation predict_invocation(const std::string& placement, const clients::body::Json& user_event, int page_size, bool dry_run); clients::body::Json predict(const std::string& placement, const clients::body::Json& user_event, int page_size = 10, bool dry_run = false) const; ListResult list_catalogs(const std::string& location_parent) const; ListResult list_catalog_items(const std::string& catalog) const; ListResult list_user_events(const std::string& event_store) const; clients::body::Json write_user_event(const std::string& event_store, const clients::body::Json& event) const; private: Caller caller_; }; } // namespace molo::google::enterprise