syntax = "proto3";

package poll_synchronization;

option go_package = "poll_synchronization";

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

// PollSynchronizationUpdate triggers when a poll is changed.
message PollSynchronizationUpdate {
  option (eventbus.owner.ldap_group) = "team-ads";
  // What type of update the poll is receiving
  PollSynchronizationUpdateType update_type = 1;
  // Type of poll being updated in the event
  PollType poll_type = 2;
  // The poll object being updated
  Poll poll = 3;
}

// Information about a poll.
message Poll {
  // This is the ID of the poll.
  string poll_id = 1;
  // This is the User/brand who owns the poll.
  string owner_id = 2;
  // This is the title of the poll.
  string title = 3;
  // This is the time the poll starts at.
  google.protobuf.Timestamp start_at = 4;
  // Time the poll ends at
  google.protobuf.Timestamp end_at = 5;
  // Duration of the poll
  google.protobuf.Duration duration = 6;
  // Controls settings on the poll.
  message PollSettings {
    // Controls whether users can vote for multiple choices.
    message MultiChoicePollSetting {
      bool enabled = 1;
    }
    MultiChoicePollSetting multi_choice = 1;
  }
  // Settings for the poll
  PollSettings settings = 7;
  // Status of a poll, describing its lifecycle state.
  enum PollStatus {
    // Something went wrong determining the state :monkaS:.
    POLL_STATUS_INVALID = 0;
    // Poll is ACTIVE and users can vote.
    POLL_STATUS_ACTIVE = 1;
    // Poll ran its entire duration and "naturally" completed. Users cannot
    // vote, but results are publicly visible.
    POLL_STATUS_COMPLETED = 2;
    // Poll was manually terminated by owner before it ran its entire duration.
    // Users cannot vote, but results are publicly visible.
    POLL_STATUS_TERMINATED = 3;
    // Poll is no longer publicly visible to users.
    POLL_STATUS_ARCHIVED = 4;
    // Poll is no longer visible to any user on Twitch.
    POLL_STATUS_MODERATED = 5;
  }
  // Current status of the poll
  PollStatus status = 8;
  // Information about a choice in a poll.
  message Choice {
    // ID of the poll choice
    string choice_id = 1;
    // Title of the choice
    string title = 2;
    // Image url of the poll choice
    string image_url = 3;
    // A breakdown of how many votes were cast for the choice.
    int64 total_votes = 4;
    // Total number of unique voters for the choice.
    int64 total_voters = 5;
  }
  // Information about the choices.
  repeated Choice choices = 9;
  // A breakdown of how many tokens were spent in the poll.
  int64 total_votes = 10;
  // Total number of unique voters in the poll. A voter can vote more than
  // once, so the number of votes don't have to match with the number of voters
  int64 total_voters = 11;
  // Duration remaining before poll completes. This will be nil if the remaining duration is 0 or
  // the poll is over as protobuf will drop what it considers empty.
  google.protobuf.Duration remaining_duration = 12;
}

// This is the type of poll being updated.
enum PollType {
  // Something went wrong determining the state.
  POLL_TYPE_INVALID = 0;
  // The poll is a channel poll
  POLL_TYPE_CHANNEL = 1;
  // The poll is an ad poll
  POLL_TYPE_AD = 2;
}

// This describes what type of update is being made to the poll. This is different than
// the PollStatus in the Poll message, as that describes the current state of the poll
// and not the reason for the eventbus event. They are similar, but are not the same.
enum PollSynchronizationUpdateType {
  // This is not a valid poll update type.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_INVALID = 0;
  // The poll has just been created by the backend service.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_CREATE = 1;
  // The poll was just updated by the backend.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_UPDATE = 2;
  // The poll has just been completed naturally.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_COMPLETE = 3;
  // The poll has been prematurely terminated by something/someone.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_TERMINATE = 4;
  // The poll has been archived so the public can't view it.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_ARCHIVE = 5;
  // The poll has been moderated so nobody can see it.
  POLL_SYNCHRONIZATION_UPDATE_TYPE_MODERATE = 6;
}
