syntax = "v1"

info (
	title:   "Node API"
	desc:    "API for ppanel"
	author:  "Tension"
	email:   "tension@ppanel.com"
	version: "0.0.1"
)

import "../types.api"

type (
	OnlineUser {
		SID int64  `json:"uid"`
		IP  string `json:"ip"`
	}
	ShadowsocksProtocol {
		Port   int    `json:"port"`
		Method string `json:"method"`
	}
	VmessProtocol {
		Host      string `json:"host"`
		Port      int    `json:"port"`
		EnableTLS *bool  `json:"enable_tls"`
		TLSConfig string `json:"tls_config"`
		Network   string `json:"network"`
		Transport string `json:"transport"`
	}
	VlessProtocol {
		Host           string `json:"host"`
		Port           int    `json:"port"`
		Network        string `json:"network"`
		Transport      string `json:"transport"`
		Security       string `json:"security"`
		SecurityConfig string `json:"security_config"`
		XTLS           string `json:"xtls"`
	}
	TrojanProtocol {
		Host      string `json:"host"`
		Port      int    `json:"port"`
		EnableTLS *bool  `json:"enable_tls"`
		TLSConfig string `json:"tls_config"`
		Network   string `json:"network"`
		Transport string `json:"transport"`
	}
	GetServerConfigRequest {
		ServerCommon
	}
	GetServerConfigResponse {
		Basic    ServerBasic `json:"basic"`
		Protocol string      `json:"protocol"`
		Config   interface{} `json:"config"`
	}
	ServerBasic {
		PushInterval int64 `json:"push_interval"`
		PullInterval int64 `json:"pull_interval"`
	}
	ServerCommon {
		Protocol  string `form:"protocol"`
		ServerId  int64  `form:"server_id"`
		SecretKey string `form:"secret_key"`
	}
	ServerUser {
		Id          int64  `json:"id"`
		UUID        string `json:"uuid"`
		SpeedLimit  int64  `json:"speed_limit"`
		DeviceLimit int64  `json:"device_limit"`
	}
	GetServerUserListRequest {
		ServerCommon
	}
	GetServerUserListResponse {
		Users []ServerUser `json:"users"`
	}
	UserTraffic {
		SID      int64 `json:"uid"`
		Upload   int64 `json:"upload"`
		Download int64 `json:"download"`
	}
	ServerPushUserTrafficRequest {
		ServerCommon
		Traffic []UserTraffic `json:"traffic"`
	}
	ServerPushStatusRequest {
		ServerCommon
		Cpu       float64 `json:"cpu"`
		Mem       float64 `json:"mem"`
		Disk      float64 `json:"disk"`
		UpdatedAt int64   `json:"updated_at"`
	}
	OnlineUsersRequest {
		ServerCommon
		Users []OnlineUser `json:"users"`
	}
	QueryServerConfigRequest {
		ServerID  int64    `path:"server_id"`
		SecretKey string   `form:"secret_key"`
		Protocols []string `form:"protocols,omitempty"`
	}
	QueryServerConfigResponse {
		TrafficReportThreshold int64          `json:"traffic_report_threshold"`
		IPStrategy             string         `json:"ip_strategy"`
		DNS                    []NodeDNS      `json:"dns"`
		Block                  []string       `json:"block"`
		Outbound               []NodeOutbound `json:"outbound"`
		Protocols              []Protocol     `json:"protocols"`
		Total                  int64          `json:"total"`
	}
)

@server (
	prefix:     v1/server
	group:      server
	middleware: ServerMiddleware
)
service ppanel {
	@doc "Get user list"
	@handler GetServerUserList
	get /user (GetServerUserListRequest) returns (GetServerUserListResponse)

	@doc "Push user Traffic"
	@handler ServerPushUserTraffic
	post /push (ServerPushUserTrafficRequest)

	@doc "Push server status"
	@handler ServerPushStatus
	post /status (ServerPushStatusRequest)

	@doc "Get server config"
	@handler GetServerConfig
	get /config (GetServerConfigRequest) returns (GetServerConfigResponse)

	@doc "Push online users"
	@handler PushOnlineUsers
	post /online (OnlineUsersRequest)
}

@server (
	prefix: v2/server
	group:  server
)
service ppanel {
	@doc "Get Server Protocol Config"
	@handler QueryServerProtocolConfig
	get /:server_id (QueryServerConfigRequest) returns (QueryServerConfigResponse)
}

