syntax = "proto3";

package service;

option go_package = "marzban_node_go/common";

message Empty {}

// Base info response message
message BaseInfoResponse {
  bool started = 1;
  string core_version = 2;
  string node_version = 3;
  string session_id = 4;
  string extra = 5;
}

enum BackendType {
  XRAY = 0;
}

message Backend {
  BackendType type = 1;
  string config = 2;
  repeated User users = 3;
  uint64 keep_alive = 4;
}

// log
message Log {
    string detail = 1;
}

// stats
message Stat {
  string name = 1;
  string type = 2;
  string link = 3;
  int64 value = 4;
}

message StatResponse {
  repeated Stat stats = 1;
}

message StatRequest {
  string name = 1;
  bool reset = 2;
}

message OnlineStatResponse {
  string name = 1;
  map<string, int64> ips = 2;
}

message BackendStatsResponse {
    uint32 num_goroutine = 1;
    uint32 num_gc = 2;
    uint64 alloc = 3;
    uint64 total_alloc = 4;
    uint64 sys = 5;
    uint64 mallocs = 6;
    uint64 frees = 7;
    uint64 live_objects = 8;
    uint64 pause_total_ns = 9;
    uint32 uptime = 10;
}

message SystemStatsResponse {
    uint64 mem_total = 1;
    uint64 mem_used = 2;
    uint64 cpu_cores = 3;
    double cpu_usage = 4;
    uint64 incoming_bandwidth_speed = 5;
    uint64 outgoing_bandwidth_speed = 6;
}

// User
message Vmess {
    string id = 1;
}

message Vless {
    string id = 1;
    string flow = 2;
}

message Trojan {
    string password = 1;
}

message Shadowsocks {
    string password = 1;
    string method = 2;
}

message Proxy {
    Vmess vmess = 1;
    Vless vless = 2;
    Trojan trojan = 3;
    Shadowsocks shadowsocks = 4;
}

message User {
    string email = 1;
    Proxy proxies = 2;
    repeated string inbounds = 3;
}

message Users {
  repeated User users = 1;
}

// Service for node management and connection
service NodeService {
  rpc Start (Backend) returns (BaseInfoResponse) {}
  rpc Stop (Empty) returns (Empty) {}
  rpc GetBaseInfo (Empty) returns (BaseInfoResponse) {}

  rpc GetLogs (Empty) returns (stream Log) {}

  rpc GetSystemStats (Empty) returns (SystemStatsResponse) {}
  rpc GetBackendStats (Empty) returns (BackendStatsResponse) {}
  rpc GetOutboundsStats (StatRequest) returns (StatResponse) {}
  rpc GetOutboundStats (StatRequest) returns (StatResponse) {}
  rpc GetInboundsStats (StatRequest) returns (StatResponse) {}
  rpc GetInboundStats (StatRequest) returns (StatResponse) {}
  rpc GetUsersStats (StatRequest) returns (StatResponse) {}
  rpc GetUserStats (StatRequest) returns (StatResponse) {}
  rpc GetUserOnlineStats (StatRequest) returns (OnlineStatResponse) {}
  
  rpc SyncUser (stream User) returns (Empty) {}
  rpc SyncUsers (Users) returns (Empty) {}
}
