syntax = "proto3";

package poll;

option go_package = "poll";

import "eventbus/change.proto";
import "eventbus/owner.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "poll/create.proto";

// PollUpdate triggers when a new poll is updated on a channel.
message PollUpdate {
  option (eventbus.owner.ldap_group) = "team-poliwag-prod";
  // The polls unique ID.
  string id = 1;
  // The ID of the user who owns the poll.
  string owned_by_user_id = 2;
  // The title of the poll.
  string title = 3;
  // The settings for the poll.
  PollSettings settings = 4;
  // The choices for the poll.
  repeated ChoiceChange choices = 5;
  // The duration the poll will run for.
  google.protobuf.Duration duration = 6;
  // The status of the poll.
  PollStatusChange status = 7;
  // Timestamp of when the poll was started.
  google.protobuf.Timestamp started_at = 8;
  // Timestamp of when the poll was ended. Nil if the poll hasn't ended.
  eventbus.change.TimestampChange ended_at = 9;
}

// ChoiceChange represents a Choice with the changes to internal fields.
message ChoiceChange {
  // The choices unique ID.
  string id = 1;
  // The title of the choice.
  string title = 2;
  // The breakdown of how many votes were cast for the choice.
  VotesChange votes = 3;
  // The total number of unique voters for the choice.
  eventbus.change.Int64Change total_voters = 4;
}

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

// Votes contains the information for the breakdown of votes.
message Votes {
  // The total number of votes cast.
  int64 total = 1;
  // The number of votes cast using bits.
  int64 bits = 2;
  // The number of votes cast using channel points.
  int64 channel_points = 3;
  // The number of votes cast using the base free votes.
  int64 base = 4;
}

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