syntax = "proto3";

option go_package = "github.com/sagernet/sing-box/service/manager_api/grpc/manager";

package manager_api.v1;

service Manager {
  rpc CreateSquad      (SquadCreate)         returns (Squad);
  rpc GetSquads        (Filters)             returns (SquadList);
  rpc GetSquadsCount   (Filters)             returns (CountReply);
  rpc GetSquad         (IdRequest)           returns (Squad);
  rpc UpdateSquad      (SquadUpdateRequest)  returns (Squad);
  rpc DeleteSquad      (IdRequest)           returns (Squad);

  rpc CreateNode       (NodeCreate)          returns (Node);
  rpc GetNodes         (Filters)             returns (NodeList);
  rpc GetNodesCount    (Filters)             returns (CountReply);
  rpc GetNode          (UuidRequest)         returns (Node);
  rpc GetNodeStatus    (UuidRequest)         returns (NodeStatusReply);
  rpc UpdateNode       (NodeUpdateRequest)   returns (Node);
  rpc DeleteNode       (UuidRequest)         returns (Node);

  rpc CreateUser       (UserCreate)          returns (User);
  rpc GetUsers         (Filters)             returns (UserList);
  rpc GetUsersCount    (Filters)             returns (CountReply);
  rpc GetUser          (IdRequest)           returns (User);
  rpc UpdateUser       (UserUpdateRequest)   returns (User);
  rpc DeleteUser       (IdRequest)           returns (User);

  rpc CreateBandwidthLimiter     (BandwidthLimiterCreate)        returns (BandwidthLimiter);
  rpc GetBandwidthLimiters       (Filters)                       returns (BandwidthLimiterList);
  rpc GetBandwidthLimitersCount  (Filters)                       returns (CountReply);
  rpc GetBandwidthLimiter        (IdRequest)                     returns (BandwidthLimiter);
  rpc UpdateBandwidthLimiter     (BandwidthLimiterUpdateRequest) returns (BandwidthLimiter);
  rpc DeleteBandwidthLimiter     (IdRequest)                     returns (BandwidthLimiter);

  rpc CreateTrafficLimiter       (TrafficLimiterCreate)          returns (TrafficLimiter);
  rpc GetTrafficLimiters         (Filters)                       returns (TrafficLimiterList);
  rpc GetTrafficLimitersCount    (Filters)                       returns (CountReply);
  rpc GetTrafficLimiter          (IdRequest)                     returns (TrafficLimiter);
  rpc UpdateTrafficLimiter       (TrafficLimiterUpdateRequest)   returns (TrafficLimiter);
  rpc DeleteTrafficLimiter       (IdRequest)                     returns (TrafficLimiter);

  rpc CreateConnectionLimiter    (ConnectionLimiterCreate)        returns (ConnectionLimiter);
  rpc GetConnectionLimiters      (Filters)                        returns (ConnectionLimiterList);
  rpc GetConnectionLimitersCount (Filters)                        returns (CountReply);
  rpc GetConnectionLimiter       (IdRequest)                      returns (ConnectionLimiter);
  rpc UpdateConnectionLimiter    (ConnectionLimiterUpdateRequest) returns (ConnectionLimiter);
  rpc DeleteConnectionLimiter    (IdRequest)                      returns (ConnectionLimiter);

  rpc CreateRateLimiter          (RateLimiterCreate)             returns (RateLimiter);
  rpc GetRateLimiters            (Filters)                       returns (RateLimiterList);
  rpc GetRateLimitersCount       (Filters)                       returns (CountReply);
  rpc GetRateLimiter             (IdRequest)                     returns (RateLimiter);
  rpc UpdateRateLimiter          (RateLimiterUpdateRequest)      returns (RateLimiter);
  rpc DeleteRateLimiter          (IdRequest)                     returns (RateLimiter);
}

message Squad {
  int32  id = 1;
  string name = 2;
  int64  created_at = 3;
  int64  updated_at = 4;
}

message SquadCreate {
  string name = 1;
}

message SquadUpdate {
  string name = 1;
}

message SquadList {
  repeated Squad values = 1;
}

message SquadUpdateRequest {
  int32       id = 1;
  SquadUpdate update = 2;
}

message Node {
  string uuid = 1;
  string name = 2;
  repeated int32 squad_ids = 3;
  int64  created_at = 4;
  int64  updated_at = 5;
}

message NodeCreate {
  string uuid = 1;
  string name = 2;
  repeated int32 squad_ids = 3;
}

message NodeUpdate {
  string name = 1;
}

message NodeList {
  repeated Node values = 1;
}

message NodeUpdateRequest {
  string     uuid = 1;
  NodeUpdate update = 2;
}

message User {
  int32  id = 1;
  repeated int32 squad_ids = 2;
  string username = 3;
  string inbound = 4;
  string type = 5;
  string uuid = 6;
  string password = 7;
  string secret = 8;
  string flow = 9;
  int32  alter_id = 10;
  int64  created_at = 11;
  int64  updated_at = 12;
}

message UserCreate {
  repeated int32 squad_ids = 1;
  string username = 2;
  string inbound = 3;
  string type = 4;
  string uuid = 5;
  string password = 6;
  string secret = 7;
  string flow = 8;
  int32  alter_id = 9;
}

message UserUpdate {
  string uuid = 1;
  string password = 2;
  string secret = 3;
  string flow = 4;
  int32  alter_id = 5;
}

message UserList {
  repeated User values = 1;
}

message UserUpdateRequest {
  int32      id = 1;
  UserUpdate update = 2;
}

message BandwidthLimiter {
  int32  id = 1;
  repeated int32 squad_ids = 2;
  string username = 3;
  string outbound = 4;
  string strategy = 5;
  string connection_type = 6;
  string mode = 7;
  repeated string flow_keys = 8;
  string speed = 9;
  uint64 raw_speed = 10;
  int64  created_at = 11;
  int64  updated_at = 12;
}

message BandwidthLimiterCreate {
  repeated int32 squad_ids = 1;
  string username = 2;
  string outbound = 3;
  string strategy = 4;
  string connection_type = 5;
  string mode = 6;
  repeated string flow_keys = 7;
  string speed = 8;
}

message BandwidthLimiterUpdate {
  string username = 1;
  string outbound = 2;
  string strategy = 3;
  string connection_type = 4;
  string mode = 5;
  repeated string flow_keys = 6;
  string speed = 7;
}

message BandwidthLimiterList {
  repeated BandwidthLimiter values = 1;
}

message BandwidthLimiterUpdateRequest {
  int32                  id = 1;
  BandwidthLimiterUpdate update = 2;
}

message TrafficLimiter {
  int32  id = 1;
  repeated int32 squad_ids = 2;
  string username = 3;
  string outbound = 4;
  string strategy = 5;
  string mode = 6;
  uint64 raw_used = 7;
  string quota = 8;
  uint64 raw_quota = 9;
  int64  created_at = 10;
  int64  updated_at = 11;
}

message TrafficLimiterCreate {
  repeated int32 squad_ids = 1;
  string username = 2;
  string outbound = 3;
  string strategy = 4;
  string mode = 5;
  string quota = 6;
}

message TrafficLimiterUpdate {
  string username = 1;
  string outbound = 2;
  string strategy = 3;
  string mode = 4;
  string quota = 5;
}

message TrafficLimiterList {
  repeated TrafficLimiter values = 1;
}

message TrafficLimiterUpdateRequest {
  int32                id = 1;
  TrafficLimiterUpdate update = 2;
}

message ConnectionLimiter {
  int32  id = 1;
  repeated int32 squad_ids = 2;
  string username = 3;
  string outbound = 4;
  string strategy = 5;
  string connection_type = 6;
  string lock_type = 7;
  uint32 count = 8;
  int64  created_at = 9;
  int64  updated_at = 10;
}

message ConnectionLimiterCreate {
  repeated int32 squad_ids = 1;
  string username = 2;
  string outbound = 3;
  string strategy = 4;
  string connection_type = 5;
  string lock_type = 6;
  uint32 count = 7;
}

message ConnectionLimiterUpdate {
  string username = 1;
  string outbound = 2;
  string strategy = 3;
  string connection_type = 4;
  string lock_type = 5;
  uint32 count = 6;
}

message ConnectionLimiterList {
  repeated ConnectionLimiter values = 1;
}

message ConnectionLimiterUpdateRequest {
  int32                   id = 1;
  ConnectionLimiterUpdate update = 2;
}

message RateLimiter {
  int32  id = 1;
  repeated int32 squad_ids = 2;
  string username = 3;
  string outbound = 4;
  string strategy = 5;
  string connection_type = 6;
  uint32 count = 7;
  string interval = 8;
  int64  created_at = 9;
  int64  updated_at = 10;
}

message RateLimiterCreate {
  repeated int32 squad_ids = 1;
  string username = 2;
  string outbound = 3;
  string strategy = 4;
  string connection_type = 5;
  uint32 count = 6;
  string interval = 7;
}

message RateLimiterUpdate {
  string username = 1;
  string outbound = 2;
  string strategy = 3;
  string connection_type = 4;
  uint32 count = 5;
  string interval = 6;
}

message RateLimiterList {
  repeated RateLimiter values = 1;
}

message RateLimiterUpdateRequest {
  int32             id = 1;
  RateLimiterUpdate update = 2;
}

message IdRequest {
  int32 id = 1;
}

message UuidRequest {
  string uuid = 1;
}

message CountReply {
  int64 count = 1;
}

message NodeStatusReply {
  string status = 1;
}

message StringList {
  repeated string values = 1;
}

message Filters {
  map<string, StringList> values = 1;
}

message Empty {}