syntax = "proto3";

package openspeak.v1;

import "proto/common.proto";

option go_package = "github.com/sorti/openspeak/pkg/api/openspeak/v1";

service PresenceService {
  rpc GetMyPresence(GetPresenceRequest) returns (UserPresence);
  rpc GetUserPresence(GetPresenceRequest) returns (UserPresence);
  rpc ListOnlineUsers(ListOnlineUsersRequest) returns (ListOnlineUsersResponse);
  rpc ListChannelMembers(ListChannelMembersRequest) returns (ListChannelMembersResponse);
  rpc SubscribePresenceEvents(SubscribePresenceRequest) returns (stream PresenceEvent);
  rpc ReportActivity(ReportActivityRequest) returns (Status);
  rpc SetPresenceStatus(SetPresenceStatusRequest) returns (UserPresence);
  rpc SetMuteStatus(SetMuteStatusRequest) returns (UserPresence);
}

message UserPresence {
  string user_id = 1;
  PresenceStatus status = 2;
  string current_channel_id = 3;
  int64 last_seen = 4;
  bool is_microphone_muted = 5;
  bool is_speaker_muted = 6;
  string client_version = 7;
  string platform = 8;
  int64 connected_at = 9;
}

enum PresenceStatus {
  OFFLINE = 0;
  ONLINE = 1;
  IDLE = 2;
  DO_NOT_DISTURB = 3;
  AWAY = 4;
}

message GetPresenceRequest {
  string user_id = 1;
}

message ListOnlineUsersRequest {
  PaginationRequest pagination = 1;
}

message ListOnlineUsersResponse {
  repeated UserPresence users = 1;
  PaginationResponse pagination = 2;
}

message ListChannelMembersRequest {
  string channel_id = 1;
  PaginationRequest pagination = 2;
}

message ListChannelMembersResponse {
  repeated UserPresence members = 1;
  PaginationResponse pagination = 2;
}

message SubscribePresenceRequest {}

message PresenceEvent {
  string event_type = 1;
  UserPresence presence = 2;
  int64 timestamp = 3;
}

message ReportActivityRequest {
  string user_id = 1;
}

message SetPresenceStatusRequest {
  PresenceStatus status = 1;
}

message SetMuteStatusRequest {
  bool microphone_muted = 1;
  bool speaker_muted = 2;
}
