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

package pb;

import "models/model_db_node.proto";
import "models/rpc_messages.proto";
import "models/model_db_table.proto";

service DBNodeService {
	// 创建数据库节点
	rpc createDBNode (CreateDBNodeRequest) returns (CreateDBNodeResponse);

	// 修改数据库节点
	rpc updateDBNode (UpdateDBNodeRequest) returns (RPCSuccess);

	// 删除节点
	rpc deleteDBNode (DeleteDBNodeRequest) returns (RPCSuccess);

	// 计算可用的数据库节点数量
	rpc countAllEnabledDBNodes (CountAllEnabledDBNodesRequest) returns (RPCCountResponse);

	// 列出单页的数据库节点
	rpc listEnabledDBNodes (ListEnabledDBNodesRequest) returns (ListEnabledDBNodesResponse);

	// 根据ID查找可用的数据库节点
	rpc findEnabledDBNode (FindEnabledDBNodeRequest) returns (FindEnabledDBNodeResponse);

	// 获取所有表信息
	rpc findAllDBNodeTables (FindAllDBNodeTablesRequest) returns (FindAllDBNodeTablesResponse);

	// 删除表
	rpc deleteDBNodeTable (DeleteDBNodeTableRequest) returns (RPCSuccess);

	// 清空表
	rpc truncateDBNodeTable (TruncateDBNodeTableRequest) returns (RPCSuccess);

	// 检查数据库节点状态
	rpc checkDBNodeStatus(CheckDBNodeStatusRequest) returns (CheckDBNodeStatusResponse);
}

// 创建数据库节点
message CreateDBNodeRequest {
	bool isOn = 1;
	string name = 2;
	string description = 3;
	string host = 4;
	int32 port = 5;
	string database = 6;
	string username = 7;
	string password = 8;
	string charset = 9;
}

message CreateDBNodeResponse {
	int64 dbNodeId = 1;
}

// 修改数据库节点
message UpdateDBNodeRequest {
	int64 dbNodeId = 1;
	string name = 2;
	string description = 3;
	bool isOn = 4;
	string host = 5;
	int32 port = 6;
	string database = 7;
	string username = 8;
	string password = 9;
	string charset = 10;
}

// 删除节点
message DeleteDBNodeRequest {
	int64 dbNodeId = 1;
}

// 计算可用的数据库节点数量
message CountAllEnabledDBNodesRequest {

}

// 列出单页的数据库节点
message ListEnabledDBNodesRequest {
	int64 offset = 1;
	int64 size = 2;
}

message ListEnabledDBNodesResponse {
	repeated DBNode dbNodes = 1;
}

// 根据ID查找可用的数据库节点
message FindEnabledDBNodeRequest {
	int64 dbNodeId = 1;
}

message FindEnabledDBNodeResponse {
	DBNode dbNode = 1;
}

// 获取所有表信息
message FindAllDBNodeTablesRequest {
	int64 dbNodeId = 1;
}

message FindAllDBNodeTablesResponse {
	repeated DBTable dbNodeTables = 1;
}

// 删除表
message DeleteDBNodeTableRequest {
	int64 dbNodeId = 1;
	string dbNodeTable = 2;
}

// 清空表
message TruncateDBNodeTableRequest {
	int64 dbNodeId = 1;
	string dbNodeTable = 2;
}

// 检查数据库节点状态
message CheckDBNodeStatusRequest {
	int64 dbNodeId = 1;
}

message CheckDBNodeStatusResponse  {
	DBNodeStatus dbNodeStatus = 1;
}