syntax = "proto3";

package prediction_event;

option go_package = "prediction_event";

import "eventbus/change.proto";
import "eventbus/owner.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "prediction_event/create.proto";

// PredictionEventUpdate triggers when a prediction event is updated on a channel.
message PredictionEventUpdate {
  option (eventbus.owner.ldap_group) = "team-predictions-prod";
  // The prediction events unique ID.
  string id = 1;
  // The ID of the channel the prediction event belongs to.
  string user_id = 2;
  // The title of the prediction event.
  string title = 3;
  // The outcomes for the prediction event.
  repeated OutcomeChange outcomes = 4;
  // The window in seconds for users to make predictions on the prediction event.
  int64 prediction_window_seconds = 5;
  // The status of the prediction event.
  PredictionEventStatusChange status = 6;
  // The ID of the winning outcome. Nil if a winning outcome hasn't been chosen.
  eventbus.change.StringValueChange winning_outcome_id = 7;
  // Timestamp of when the prediction event was created.
  google.protobuf.Timestamp created_at = 8;
  // Timestamp of when the prediction event was locked. Nil if the prediction event hasn't been locked.
  eventbus.change.TimestampChange locked_at = 9;
  // Timestamp of when the prediction event ended. Nil if the prediction event hasn't ended.
  eventbus.change.TimestampChange ended_at = 10;
}

// OutcomeChange represents an Outcome with the changes to internal fields.
message OutcomeChange {
  // The outcomes unique ID.
  string id = 1;
  // The color assigned to the outcome.
  OutcomeColor color = 2;
  // The title of the outcome.
  string title = 3;
  // The total points used on the outcome.
  eventbus.change.Int64Change total_points = 4;
  // The total users who selected the outcome.
  eventbus.change.Int64Change total_users = 5;
  // The predictions of the top predictors by points used on the outcome.
  PredictionArrayChange top_predictors = 6;
}

// PredictionArrayChange represents the state change for an array of Predictions.
message PredictionArrayChange {
  bool updated = 1;
  repeated Prediction value = 2;
  bool has_old_value = 3;
  repeated Prediction old_value = 4;
}

// Prediction contains the information for a users prediction in a prediction event.
message Prediction {
  // The predictions unique ID.
  string id = 1;
  // The ID of the user who made the prediction.
  string user_id = 2;
  // The number of points used by the user.
  int64 points = 3;
  // The result of the prediction. Nil if the prediction event hasn't ended yet.
  PredictionResult result = 4;
}

// PredictionResult contains the information for the result of a users prediction in a prediction event.
message PredictionResult {
  // The type of result.
  PredictionResultType type = 1;
  // The amount of points won based on the result of the prediction. Nil if the prediction event hasn't ended or the prediction wasn't won.
  google.protobuf.Int64Value points_won = 2;
}

// PredictionEventStatusChange represents the state change for a PredictionEventStatus.
message PredictionEventStatusChange {
  bool updated = 1;
  PredictionEventStatus value = 2;
  bool has_old_value = 3;
  PredictionEventStatus old_value = 4;
}

// PredictionResultType is the different results that a prediction can have.
enum PredictionResultType {
  PREDICTION_RESULT_TYPE_INVALID = 0;
  // The prediction has been refunded.
  PREDICTION_RESULT_TYPE_REFUND = 1;
  // The prediction won.
  PREDICTION_RESULT_TYPE_WIN = 2;
  // The prediction lost.
  PREDICTION_RESULT_TYPE_LOSE = 3;
}
