syntax = "proto3";
import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";

package code.justin.tv.commerce.percy;
option go_package = "rpc";

service Percy {
    rpc HealthCheck(HealthCheckReq) returns (HealthCheckResp) {};

    rpc GetHypeTrainConfig(GetHypeTrainConfigReq) returns (GetHypeTrainConfigResp) {};

    rpc UpdateHypeTrainConfig(UpdateHypeTrainConfigReq) returns (UpdateHypeTrainConfigResp) {};

    rpc UnsetHypeTrainConfig(UnsetHypeTrainConfigReq) returns (UnsetHypeTrainConfigResp) {};

    rpc GetOngoingHypeTrain(GetOngoingHypeTrainReq) returns (GetOngoingHypeTrainResp) {};

    rpc UpsertHypeTrain(UpsertHypeTrainReq) returns (UpsertHypeTrainResp) {};

    rpc CanStartHypeTrain(CanStartHypeTrainReq) returns (CanStartHypeTrainResp) {};

    rpc GetHypeTrainBadges(GetHypeTrainBadgesReq) returns (GetHypeTrainBadgesResp) {};

    rpc HelixGetMostRecentHypeTrain(HelixGetMostRecentHypeTrainReq) returns (HelixGetMostRecentHypeTrainResp) {};

    rpc AdminGrantHypeTrainRewards(AdminGrantHypeTrainRewardsReq) returns (AdminGrantHypeTrainRewardsResp) {};
}

message HealthCheckReq {}

message HealthCheckResp {
    string response = 1;
}

message GetHypeTrainConfigReq {
    string channel_id = 1;
}

message GetHypeTrainConfigResp {
    string channel_id = 1;
    HypeTrainConfig config = 2;
}

message UpdateHypeTrainConfigReq {
    string channel_id = 1;
    google.protobuf.BoolValue enabled = 2;
    google.protobuf.Int64Value num_of_events_to_kickoff = 3;
    Difficulty difficulty = 4;
    google.protobuf.Int64Value cooldown_duration_minutes = 5;
    google.protobuf.StringValue callout_emote_id = 6;
    google.protobuf.StringValue theme_color = 7;
}

message UpdateHypeTrainConfigResp {
    string channel_id = 1;
    HypeTrainConfig config = 2;
}

message UnsetHypeTrainConfigReq {
    string channel_id = 1;
    google.protobuf.BoolValue enabled = 2;
    google.protobuf.BoolValue num_of_events_to_kickoff = 3;
    google.protobuf.BoolValue difficulty = 4;
    google.protobuf.BoolValue cooldown_duration_minutes = 5;
    google.protobuf.BoolValue callout_emote_id = 6;
    google.protobuf.BoolValue theme_color = 7;
}

message UnsetHypeTrainConfigResp {
    string channel_id = 1;
    HypeTrainConfig config = 2;
}

message HypeTrainConfig {
    bool enabled = 1;
    KickoffConfig kickoff_config = 2;
    int64 cooldown_duration_minutes = 3;
    int64 level_duration_seconds = 4;
    Difficulty difficulty = 5;
    repeated DifficultySetting difficulty_settings = 6;
    repeated ConductorReward conductor_rewards = 7;
    repeated ParticipationConversionRate participation_conversion_rates = 8;
    repeated NotificationThreshold notification_thresholds = 9;
    bool is_whitelisted = 10;
    google.protobuf.Timestamp reward_end_date = 11;
    string callout_emote_id = 12;
    string theme_color = 13;
}

message KickoffConfig {
    int64 num_of_events = 1;
    int64 min_points = 2;
    int64 duration_seconds = 3;
}

enum Difficulty {
    UNKNOWN_DIFFICULTY = 0;
    EASY = 1;
    MEDIUM = 2;
    HARD = 3;
    SUPER_HARD = 4;
    INSANE = 5;
}

message DifficultySetting {
    Difficulty difficulty = 1;
    repeated LevelSetting level_settings = 2;
}

message LevelSetting {
    int64 level = 1;
    int64 goal = 2;
    repeated Reward rewards = 3;
}

message Reward  {
    string id = 1;
    string group_id = 2;
    RewardType type = 3;
}

enum RewardType {
    UNKNOWN_REWARD_TYPE = 0;
    EMOTE = 1;
    BADGE = 2;
}

message ConductorReward {
    ParticipationSource source = 1;
    ConductorType type = 2;
    repeated Reward rewards = 3;
}

enum ConductorType {
    UNKNOWN_CONDUCTOR_TYPE = 0;
    CURRENT = 1;
    FORMER = 2;
}

message Conductor {
    ParticipationSource source = 1;
    string user_id = 2;
    repeated Participation participations = 3;
}

message ParticipationConversionRate {
    ParticipationSource source = 1;
    ParticipationAction action = 2;
    int64 rate = 3;
}

message NotificationThreshold {
    ParticipationSource source = 1;
    ParticipationAction action = 2;
    int64 quantity = 3;
}

message HypeTrain {
    string channel_id = 1;
    string id = 2;
    google.protobuf.Timestamp started_at = 3;
    google.protobuf.Timestamp expires_at = 4;
    google.protobuf.Timestamp updated_at = 5;
    google.protobuf.Timestamp ended_at = 6;
    EndingReason ending_reason = 7;
    HypeTrainConfig config = 8;
    repeated Conductor conductors = 9;
    repeated Participation participations = 10;
    bool is_active = 11;
    Progress level_progress = 12;
}

message Progress {
    LevelSetting setting = 1;
    int64 progression = 2;
    int64 goal = 3;
    int64 total = 4;
    int64 remaining_seconds = 5;
}

message Participation {
    ParticipationSource source = 1;
    ParticipationAction action = 2;
    int64 quantity = 3;
}

enum ParticipationSource {
    UNKNOWN_SOURCE = 0;
    BITS = 1;
    SUBS = 2;
    ADMIN_SOURCE = 3;
}

enum ParticipationAction {
    UNKNOWN_ACTION = 0;
    CHEER = 1;
    EXTENSION = 2;
    POLL = 3;
    TIER_1_SUB = 4;
    TIER_2_SUB = 5;
    TIER_3_SUB = 6;
    TIER_1_GIFTED_SUB = 7;
    TIER_2_GIFTED_SUB = 8;
    TIER_3_GIFTED_SUB = 9;
    ADMIN_ACTION = 10;
}

enum EndingReason {
    UNKNOWN_REASON = 0;
    IN_PROGRESS = 1;
    EXPIRED = 2;
    COMPLETED = 3;
}

message GetOngoingHypeTrainReq {
    string channel_id = 1;
}

message GetOngoingHypeTrainResp {
    HypeTrain hype_train = 1;
}

message UpsertHypeTrainReq {
    HypeTrain hype_train = 1;
}

message UpsertHypeTrainResp {}

message CanStartHypeTrainReq {
    string channel_id = 1;
}

message CanStartHypeTrainResp {
    bool can_start_hype_train = 1;
}

message GetHypeTrainBadgesReq {
    string user_id = 1;
    string channel_id = 2;
}

message GetHypeTrainBadgesResp {
    repeated HypeTrainBadge badges = 1;
}

message HypeTrainBadge {
    BadgeType badge_type = 1;
}

enum BadgeType {
    UNKNOWN_BADGE = 0;
    CURRENT_CONDUCTOR = 1;
    FORMER_CONDUCTOR = 2;
}

message HelixGetMostRecentHypeTrainReq {
    string channel_id = 1;
}

message Contribution {
    string type = 1;
    string user = 2;
    int64 total = 3;
}

message HelixGetMostRecentHypeTrainResp {
    string hype_train_id = 1;
    google.protobuf.Timestamp started_at = 2;
    google.protobuf.Timestamp expires_at = 3;
    google.protobuf.Timestamp cooldown_end_time = 4;
    int64 level = 5;
    int64 goal = 6;
    int64 total = 7;
    repeated Contribution top_contributions = 8;
    Contribution last_contribution = 9;
}

message AdminGrantHypeTrainRewardsReq {
    string channel_id = 1;
    string user_id = 2;
    oneof hype_train_identifier {
        string hype_train_id = 3;
        google.protobuf.Timestamp participated_at = 4;
    }
}

message AdminGrantHypeTrainRewardsResp {
    string channel_id =1;
    string user_id = 2;
    HypeTrain hype_train = 3;
    repeated Reward granted_rewards = 4;
    repeated Reward user_owned_rewards = 5;
    repeated Participation participation_totals = 6;
}
