syntax = "proto3";
option go_package = "./pb";

package pb;

import "models/model_report_node.proto";
import "models/model_report_task.proto";
import "models/rpc_messages.proto";

// 监控终端服务
service ReportNodeService {
	// 添加终端
	rpc createReportNode(CreateReportNodeRequest) returns (CreateReportNodeResponse);

	// 删除终端
	rpc deleteReportNode(DeleteReportNodeRequest) returns (RPCSuccess);

	// 修改终端
	rpc updateReportNode(UpdateReportNodeRequest) returns (RPCSuccess);

	// 计算终端数量
	rpc countAllEnabledReportNodes(CountAllEnabledReportNodesRequest) returns (RPCCountResponse);

	// 列出单页终端
	rpc listEnabledReportNodes(ListEnabledReportNodesRequest) returns (ListEnabledReportNodesResponse);

	// 查找单个终端
	rpc findEnabledReportNode(FindEnabledReportNodeRequest) returns (FindEnabledReportNodeResponse);

	// 终端stream
	rpc reportNodeStream (stream ReportNodeStreamMessage) returns (stream ReportNodeStreamMessage);

	// 更新节点状态
	rpc updateReportNodeStatus (UpdateReportNodeStatusRequest) returns (RPCSuccess);

	// 获取当前节点信息
	rpc findCurrentReportNodeConfig (FindCurrentReportNodeConfigRequest) returns (FindCurrentReportNodeConfigResponse);

	// 读取任务
	rpc findReportNodeTasks(FindReportNodeTasksRequest) returns (FindReportNodeTasksResponse);

	// 取得最新的版本号
	rpc findLatestReportNodeVersion(FindLatestReportNodeVersionRequest) returns (FindLatestReportNodeVersionResponse);

	// 计算任务数量
	rpc countAllReportNodeTasks(CountAllReportNodeTasksRequest) returns (RPCCountResponse);

	// 列出单页任务
	rpc listReportNodeTasks(ListReportNodeTasksRequest) returns (ListReportNodeTasksResponse);

	// 修改全局设置
	rpc updateReportNodeGlobalSetting(UpdateReportNodeGlobalSetting) returns (RPCSuccess);

	// 读取全局设置
	rpc readReportNodeGlobalSetting(ReadReportNodeGlobalSettingRequest) returns (ReadReportNodeGlobalSettingResponse);
}

// 添加终端
message CreateReportNodeRequest {
	string name = 1;
	string location = 2;
	string isp = 3;
	repeated string allowIPs = 4;
	repeated int64 reportNodeGroupIds = 5;
}

message CreateReportNodeResponse {
	int64 reportNodeId = 1;
}

// 删除终端
message DeleteReportNodeRequest {
	int64 reportNodeId = 1;
}

// 修改终端
message UpdateReportNodeRequest{
	int64 reportNodeId = 1;
	string name = 2;
	string location = 3;
	string isp = 4;
	repeated string allowIPs = 5;
	bool isOn = 6;
	repeated int64 reportNodeGroupIds = 7;
}

// 计算终端数量
message CountAllEnabledReportNodesRequest {
	string keyword = 1;
	int64 reportNodeGroupId = 2;
}

// 列出单页终端
message ListEnabledReportNodesRequest {
	string keyword = 1;
	int64 reportNodeGroupId = 4;
	int64 offset = 2;
	int64 size = 3;
}

message ListEnabledReportNodesResponse {
	repeated ReportNode reportNodes = 1;
}

// 查找单个终端
message FindEnabledReportNodeRequest{
	int64 reportNodeId = 1;
}

message FindEnabledReportNodeResponse {
	ReportNode reportNode = 1;
}

// 终端stream
message ReportNodeStreamMessage {
	int64 reportNodeId = 1;
	int64 requestId = 2;
	int32 timeoutSeconds = 3;
	string code = 4;
	bytes dataJSON = 5;
	bool isOk = 6;
	string message = 7;
}

// 更新节点状态
message UpdateReportNodeStatusRequest {
	bytes statusJSON = 1;
}


// 获取当前节点信息
message FindCurrentReportNodeConfigRequest {

}

message FindCurrentReportNodeConfigResponse {
	bytes reportNodeJSON = 1;
}

// 读取任务
message FindReportNodeTasksRequest {

}

message FindReportNodeTasksResponse {
	bytes ipAddrTasksJSON = 1;
}

// 取得最新的版本号
message FindLatestReportNodeVersionRequest {

}

message FindLatestReportNodeVersionResponse {
	string version = 1;
}

// 计算任务数量
message CountAllReportNodeTasksRequest {
	string role = 1;
	int64 nodeClusterId = 2;
	string type = 3;
}

// 列出单页任务
message ListReportNodeTasksRequest {
	string role = 1;
	int64 nodeClusterId = 2;
	string type = 3;
	int64 offset = 4;
	int64 size = 5;
}

message ListReportNodeTasksResponse {
	repeated IPAddrReportTask ipAddrReportTasks = 1;
}

// 修改全局设置
message UpdateReportNodeGlobalSetting {
	bytes settingJSON = 1;
}

// 读取全局设置
message ReadReportNodeGlobalSettingRequest {
}

message ReadReportNodeGlobalSettingResponse {
	bytes settingJSON = 1;
}