syntax = "proto3";

package crabs.evening_detective;

import "google/api/annotations.proto";

option go_package = "pkg/proto";

service EveningDetective {
  rpc Ping(PingReq) returns (PingRsp) {
    option (google.api.http) = {
      get: "/ping"
    };
  }

  rpc AddTeams(AddTeamsReq) returns (AddTeamsRsp) {
    option (google.api.http) = {
      post: "/teams",
      body: "*"
    };
  }

  rpc GetTeams(GetTeamsReq) returns (GetTeamsRsp) {
    option (google.api.http) = {
      get: "/teams"
    };
  }

  rpc GetTeamsCSV(GetTeamsCSVReq) returns (GetTeamsCSVRsp) {
    option (google.api.http) = {
      get: "/csv"
    };
  }

  rpc GetTeam(GetTeamReq) returns (GetTeamRsp) {
    option (google.api.http) = {
      get: "/team"
    };
  }

  rpc AddAction(AddActionReq) returns (AddActionRsp) {
    option (google.api.http) = {
      post: "/team/actions",
      body: "*"
    };
  }

  rpc GetGame(GetGameReq) returns (GetGameRsp) {
    option (google.api.http) = {
      get: "/game"
    };
  }

  rpc GameStart(GameStartReq) returns (GameStartRsp) {
    option (google.api.http) = {
      post: "/game/start",
      body: "*"
    };
  }

  rpc GameStop(GameStopReq) returns (GameStopRsp) {
    option (google.api.http) = {
      post: "/game/stop",
      body: "*"
    };
  }

  rpc GiveApplications(GiveApplicationsReq) returns (GiveApplicationsRsp) {
    option (google.api.http) = {
      post: "/teams/{teamId}/applications",
      body: "*"
    };
  }

  rpc DownloadTeamsQrCodesFile(DownloadTeamsQrCodesFileReq) returns (DownloadTeamsQrCodesFileRsp) {
    option (google.api.http) = {
      get: "/teams/pdf"
    };
  }

  rpc GetGraph(GetGraphReq) returns (GetGraphRsp) {
    option (google.api.http) = {
      get: "/graph"
    };
  }

  rpc UpdateNode(UpdateNodeReq) returns (UpdateNodeRsp) {
    option (google.api.http) = {
      put : "/graph/nodes",
      body: "*"
    };
  }
}

message PingReq {}

message PingRsp {}

message AddTeamsReq {
  repeated Team teams = 1;
}

message Team {
  string name = 1;
}

message AddTeamsRsp {
  repeated TeamFull teams = 1;
}

message TeamFull {
  int64  id       = 1;
  string name     = 2;
  string password = 3;
}

message GetTeamsReq {}

message GetTeamsRsp {
  repeated TeamAdvanced teams = 1;
}

message GetTeamsCSVReq {}

message GetTeamsCSVRsp {
  string data = 1;
}

message TeamAdvanced {
  int64                id           = 1;
  string               name         = 2;
  string               password     = 3;
  string               url          = 4;
  int64                spendTime    = 5;
  repeated Application applications = 6;
}

message Application {
  int64  id     = 1;
  string name   = 2;
  string state  = 3;
  string number = 4;
}

message Door {
  string code = 1;
  string name = 2;
  bool   show = 3;
}

message GetTeamReq {}

message GetTeamRsp {
  string          name    = 1;
  repeated Action actions = 2;
}

message AddActionReq {
  string place = 1;
}

message AddActionRsp {}

message Action {
  int64                id           = 1;
  string               place        = 2;
  string               name         = 3;
  string               text         = 4;
  string               image        = 5;
  repeated Application applications = 6;
  bool                 hidden       = 7;
  repeated Door        doors        = 8;
}

message GetGameReq {}

message GetGameRsp {
  string state   = 1;
  string startAt = 2;
  string endAt   = 3;
}

message GameStartReq {}

message GameStartRsp {}

message GameStopReq {
  int64 timeSeconds = 1;
}

message GameStopRsp {}

message GiveApplicationsReq {
  int64                teamId       = 1;
  repeated Application applications = 2;
}

message GiveApplicationsRsp {}

message DownloadTeamsQrCodesFileReq {}

message DownloadTeamsQrCodesFileRsp {
  bytes result = 1;
}

message GetGraphReq {}

message GetGraphRsp {
  repeated GraphNode nodes      = 1;
  repeated Edge      edges      = 2;
  int32              countNodes = 3;
  int32              countEdges = 4;

  message Edge {
    string from   = 1;
    string to     = 2;
    string arrows = 3;
    string type   = 4;
  }
}

message UpdateNodeReq {
  string    code = 1;
  GraphNode node = 2;
}

message UpdateNodeRsp {}

message GraphNode {
  string                    code         = 1;
  string                    name         = 2;
  string                    text         = 3;
  repeated GraphApplication applications = 4;
}

message GraphApplication {
  string name = 1;
}
