syntax = "proto3";

import "google/protobuf/timestamp.proto";

package code.justin.tv.commerce.petozi;
option go_package = "petozi";

// Supported Endpoints

service Petozi {
    // health check
    rpc HealthCheck (HealthCheckReq) returns (HealthCheckResp) {};

    // Bits Types
    rpc GetBitsType (GetBitsTypeReq) returns (GetBitsTypeResp) {};
    rpc GetBitsTypes (GetBitsTypesReq) returns (GetBitsTypesResp) {};
    rpc PutBitsType (PutBitsTypeReq) returns (PutBitsTypeResp) {};

    // Bits Products
    rpc PutBitsProduct(PutBitsProductReq) returns (PutBitsProductResp) {};
    rpc GetBitsProduct(GetBitsProductReq) returns (GetBitsProductResp) {};
    rpc GetBitsProducts(GetBitsProductsReq) returns (GetBitsProductsResp) {};

    // ADMIN OPERATIONS
    rpc ResetCaches(ResetCachesReq) returns (ResetCachesResp) {};
}

message HealthCheckReq {
}

message HealthCheckResp {
}

message GetBitsTypeReq {
    string id = 1;
}

message GetBitsTypeResp {
    BitsType bits_type = 1;
}

message GetBitsTypesReq {
}

message GetBitsTypesResp {
    repeated BitsType bits_types = 1;
}

message PutBitsTypeReq {
    BitsType bits_type = 1;
}

message PutBitsTypeResp {
}

message BitsType {
    string id                                      = 1;
    string display_name                            = 2;
    bool is_paid                                   = 3;
    bool is_promotional                            = 4;
    double cost_per_bits_usc                       = 5;
    EntitlementSourceType entitlement_source_type  = 6;
    // Deprecated only for our FABS migration
    uint32 spend_order                             = 7;
    BusinessAttribution business_attribution       = 8;
}

message PutBitsProductReq {
    BitsProduct new_bits_product = 1;
}

message PutBitsProductResp {
}

message GetBitsProductReq {
    string id         = 1;
    Platform platform = 2;
}

message GetBitsProductResp {
    BitsProduct bits_product = 1;
}

message GetBitsProductsReq {
    bool use_in_memory_cache = 1;
}

message GetBitsProductsResp {
    repeated BitsProduct bits_products = 1;
}

message ResetCachesReq {}

message ResetCachesResp {}

message BitsProduct {
    string id                            = 1;
    string display_name                  = 2;
    Platform platform                    = 3;
    string bits_type_id                  = 4;
    uint64 quantity                      = 5;
    uint32 max_purchasable_quantity      = 6;
    Promo promo                          = 7;
    bool show_when_logged_out            = 8;
    string pricing_id                    = 9;
    string offer_id                      = 10;
}

message Promo {
    string id                       = 1;
    PromoType type                  = 2;
    google.protobuf.Timestamp start = 3;
    google.protobuf.Timestamp end   = 4;
    repeated string whitelisted_ids = 5;
}

enum Platform {
    NONE    = 0;
    AMAZON  = 1;
    PAYPAL  = 2;
    IOS     = 3;
    ANDROID = 4;
    XSOLLA  = 5;
    PHANTO  = 6;
    STRIPE  = 7;
    VANTIV  = 8;
    WALLET  = 9;
    UNKNOWN = 10;
}

enum EntitlementSourceType {
    WEB_PURCHASE       = 0;
    IN_APP_PURCHASE    = 1;
    DIRECT_ENTITLEMENT = 2;
    REDEEMED_CODE      = 3;
}

enum BusinessAttribution {
    PAYMENT_TRANSACTION       = 0;
    WATEB                     = 1;
    CUSTOMER_SERVICE_GOODWILL = 2;
    TESTING                   = 4;
    EXTENSIONS                = 5;
    SECOND_PARTY_AMAZON       = 6;
    FIRST_PARTY_MULTIPURPOSE  = 7;
    FIRST_PARTY_MARKETING     = 8;
}

enum PromoType {
    SINGLE_PURCHASE         = 0;
    FIRST_TIME_PURCHASE     = 1;
    PRIME_SINGLE_PURCHASE   = 2;
    STAFF_ONLY_PROMO        = 3;
}