#ifndef COMPONENTS_COMMERCE_CORE_SUBSCRIPTIONS_COMMERCE_SUBSCRIPTION_H_
#define COMPONENTS_COMMERCE_CORE_SUBSCRIPTIONS_COMMERCE_SUBSCRIPTION_H_
#include <stdint.h>
#include <optional>
#include <string>
* To add a new SubscriptionType / IdentifierType / ManagementType:
* 1. Define the type in the enum class in commerce_subscription.h.
* 2. Update the conversion methods between the type and std::string in
* commerce_subscription.cc.
* 3. Add the corresponding entry in {@link
* commerce_subscription_db_content.proto} to ensure the storage works
* correctly.
*/
namespace commerce {
enum class SubscriptionType {
kTypeUnspecified = 0,
kPriceTrack = 1,
};
enum class IdentifierType {
kIdentifierTypeUnspecified = 0,
kOfferId = 1,
kProductClusterId = 2,
};
enum class ManagementType {
kTypeUnspecified = 0,
kChromeManaged = 1,
kUserManaged = 2,
};
struct UserSeenOffer {
UserSeenOffer(std::string offer_id,
long user_seen_price,
std::string country_code,
std::string locale);
UserSeenOffer(const UserSeenOffer&);
UserSeenOffer& operator=(const UserSeenOffer&);
~UserSeenOffer();
std::string offer_id;
long user_seen_price;
std::string country_code;
std::string locale;
};
extern const int64_t kUnknownSubscriptionTimestamp;
extern const uint64_t kInvalidSubscriptionId;
struct CommerceSubscription {
CommerceSubscription(
SubscriptionType type,
IdentifierType id_type,
std::string id,
ManagementType management_type,
int64_t timestamp = kUnknownSubscriptionTimestamp,
std::optional<UserSeenOffer> user_seen_offer = std::nullopt);
CommerceSubscription(const CommerceSubscription&);
CommerceSubscription& operator=(const CommerceSubscription&);
~CommerceSubscription();
SubscriptionType type;
IdentifierType id_type;
std::string id;
ManagementType management_type;
int64_t timestamp;
std::optional<UserSeenOffer> user_seen_offer;
};
std::string SubscriptionTypeToString(SubscriptionType type);
SubscriptionType StringToSubscriptionType(const std::string& s);
std::string SubscriptionIdTypeToString(IdentifierType type);
IdentifierType StringToSubscriptionIdType(const std::string& s);
std::string SubscriptionManagementTypeToString(ManagementType type);
ManagementType StringToSubscriptionManagementType(const std::string& s);
std::string GetStorageKeyForSubscription(
const CommerceSubscription& subscription);
}
#endif