syntax = "proto3";

package photon.imessage.v1;

import "photon/imessage/v1/poll_types.proto";
import "photon/imessage/v1/streaming.proto";

option swift_prefix = "PIMsg_";


// ---------------------------------------------------------------------------
// Service
// ---------------------------------------------------------------------------

// Apple Polls (iOS 18+) authoring and observation.
//
// Every write returns the resulting `PollInfo` snapshot.
//
// Durable poll changes flow through `SubscribePollEvents`. For gap-free
// reconnect, pair it with `EventService.CatchUpEvents`.
service PollService {

  // Writes
  rpc CreatePoll(CreatePollRequest) returns (PollResponse);

  rpc VotePoll(VotePollRequest) returns (PollResponse);

  rpc UnvotePoll(UnvotePollRequest) returns (PollResponse);

  rpc AddPollOption(AddPollOptionRequest) returns (PollResponse);

  // Reads
  rpc GetPoll(GetPollRequest) returns (PollResponse);

  // Streams
  rpc SubscribePollEvents(SubscribePollEventsRequest) returns (stream SubscribePollEventsResponse);

}


// ---------------------------------------------------------------------------
// Writes
// ---------------------------------------------------------------------------

message CreatePollRequest {

  string chat_guid = 1;

  string title = 2;

  repeated string options = 3;

  optional string client_message_id = 100;

}


message PollResponse {

  PollInfo poll = 1;

}


message VotePollRequest {

  string poll_message_guid = 1;

  string option_identifier = 2;

  optional string client_message_id = 100;

}


message UnvotePollRequest {

  string poll_message_guid = 1;

  optional string client_message_id = 100;

}


message AddPollOptionRequest {

  string poll_message_guid = 1;

  string option_text = 2;

  optional string client_message_id = 100;

}


// ---------------------------------------------------------------------------
// Reads
// ---------------------------------------------------------------------------

message GetPollRequest {

  string poll_message_guid = 1;

}


// ---------------------------------------------------------------------------
// Streams
// ---------------------------------------------------------------------------

message SubscribePollEventsRequest {

  // Absent = subscribe to every poll the caller can observe.
  optional string poll_message_guid = 1;

}


message SubscribePollEventsResponse {

  // Monotonic global sequence shared with `EventService.CatchUpEvents`
  // and every other `Subscribe*` stream. Absent on heartbeat frames.
  optional uint64 sequence = 1;

  oneof payload {

    PollChangeEvent poll_changed = 10;

    Heartbeat heartbeat = 99;

  }

}
