syntax = "proto3";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "NadekoBot.Coordinator";

package nadekobot;

service Coordinator {
  // sends update to coordinator to let it know that the shard is alive
  rpc Heartbeat(HeartbeatRequest) returns (HeartbeatReply);
  // restarts a shard given the id
  rpc RestartShard(RestartShardRequest) returns (RestartShardReply);
  // reshards given the new number of shards
  rpc Reshard(ReshardRequest) returns (ReshardReply);
  // Reload config
  rpc Reload(ReloadRequest) returns (ReloadReply);
  // Gets status of a single shard
  rpc GetStatus(GetStatusRequest) returns (GetStatusReply);
  // Get status of all shards
  rpc GetAllStatuses(GetAllStatusesRequest) returns (GetAllStatusesReply);
  // Restarts all shards. Queues them to be restarted at a normal rate. Setting Nuke to true will kill all shards right
  // away
  rpc RestartAllShards(RestartAllRequest) returns (RestartAllReply);
  
  // kill coordinator (and all shards as a consequence)
  rpc Die(DieRequest) returns (DieReply);
  
  rpc SetConfigText(SetConfigTextRequest) returns (SetConfigTextReply);
  
  rpc GetConfigText(GetConfigTextRequest) returns (GetConfigTextReply);
}

enum ConnState {
  Disconnected = 0;
  Connecting = 1;
  Connected = 2;
}

message HeartbeatRequest {
  int32 shardId = 1;
  int32 guildCount = 2;  
  ConnState state = 3;
}

message HeartbeatReply {
  bool gracefulImminent = 1;
}

message RestartShardRequest {
  int32 shardId = 1;
  // should it be queued for restart, set false to kill it and restart immediately with priority
  bool queue = 2;
}

message RestartShardReply {
  
}

message ReshardRequest {
  int32 shards = 1;
}

message ReshardReply {
  
}

message ReloadRequest {
  
}

message ReloadReply {
  
}

message GetStatusRequest {
 int32 shardId = 1; 
}

message GetStatusReply {
  int32 shardId = 1;
  ConnState state = 2;
  int32 guildCount = 3;
  google.protobuf.Timestamp lastUpdate = 4;
  bool scheduledForRestart = 5;
  google.protobuf.Timestamp startedAt = 6;
}

message GetAllStatusesRequest {
  
}

message GetAllStatusesReply {
	repeated GetStatusReply Statuses = 1;
}

message RestartAllRequest {
  bool nuke = 1;
}

message RestartAllReply {
  
}

message DieRequest {
  bool graceful = 1;
}

message DieReply {
  
}

message GetConfigTextRequest {
  
}

message GetConfigTextReply {
  string configYml = 1;
}

message SetConfigTextRequest {
  string configYml = 1;
}

message SetConfigTextReply {
  bool success = 1;
  string error = 2;
}