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

package pb;

import "models/rpc_messages.proto";
import "models/model_user.proto";
import "models/model_user_feature.proto";
import "models/model_node_value.proto";

// 用户相关服务
service UserService {
	// 创建用户
	rpc createUser (CreateUserRequest) returns (CreateUserResponse);

	// 修改用户
	rpc updateUser (UpdateUserRequest) returns (RPCSuccess);

	// 删除用户
	rpc deleteUser (DeleteUserRequest) returns (RPCSuccess);

	// 计算用户数量
	rpc countAllEnabledUsers (CountAllEnabledUsersRequest) returns (RPCCountResponse);

	// 列出单页用户
	rpc listEnabledUsers (ListEnabledUsersRequest) returns (ListEnabledUsersResponse);

	// 查询单个用户信息
	rpc findEnabledUser (FindEnabledUserRequest) returns (FindEnabledUserResponse);

	// 检查用户名是否存在
	rpc checkUserUsername (CheckUserUsernameRequest) returns (CheckUserUsernameResponse);

	// 登录
	rpc loginUser (LoginUserRequest) returns (LoginUserResponse);

	// 修改用户基本信息
	rpc updateUserInfo (UpdateUserInfoRequest) returns (RPCSuccess);

	// 修改用户登录信息
	rpc updateUserLogin (UpdateUserLoginRequest) returns (RPCSuccess);

	// 取得用户Dashboard数据
	rpc composeUserDashboard (ComposeUserDashboardRequest) returns (ComposeUserDashboardResponse);

	// 获取用户所在的集群ID
	rpc findUserNodeClusterId (FindUserNodeClusterIdRequest) returns (FindUserNodeClusterIdResponse);

	// 设置用户能使用的功能
	rpc updateUserFeatures (UpdateUserFeaturesRequest) returns (RPCSuccess);

	// 获取用户所有的功能列表
	rpc findUserFeatures (FindUserFeaturesRequest) returns (FindUserFeaturesResponse);

	// 获取所有的功能定义
	rpc findAllUserFeatureDefinitions (FindAllUserFeatureDefinitionsRequest) returns (FindAllUserFeatureDefinitionsResponse);

	// 组合全局的看板数据
	rpc composeUserGlobalBoard (ComposeUserGlobalBoardRequest) returns (ComposeUserGlobalBoardResponse);
}

// 创建用户
message CreateUserRequest {
	string username = 1;
	string password = 2;
	string fullname = 3;
	string mobile = 4;
	string tel = 5;
	string email = 6;
	string remark = 7;
	string source = 8;
	int64 nodeClusterId = 9;
}

message CreateUserResponse {
	int64 userId = 1;
}

// 修改用户
message UpdateUserRequest {
	int64 userId = 1;
	string username = 2;
	string password = 3;
	string fullname = 4;
	string mobile = 5;
	string tel = 6;
	string email = 7;
	string remark = 8;
	bool isOn = 9;
	int64 nodeClusterId = 10;
}

// 删除用户
message DeleteUserRequest {
	int64 userId = 1;
}

// 计算用户数量
message CountAllEnabledUsersRequest {
	string keyword = 1;
}

// 列出单页用户
message ListEnabledUsersRequest {
	string keyword = 1;
	int64 offset = 2;
	int64 size = 3;
}

message ListEnabledUsersResponse {
	repeated User users = 1;
}

// 查询单个用户信息
message FindEnabledUserRequest {
	int64 userId = 1;
}

message FindEnabledUserResponse {
	User user = 1;
}

// 检查用户名是否存在
message CheckUserUsernameRequest {
	int64 userId = 1;
	string username = 2;
}

message CheckUserUsernameResponse {
	bool exists = 1;
}

// 登录
message LoginUserRequest {
	string username = 1;
	string password = 2;
}

message LoginUserResponse {
	int64 userId = 1;
	bool isOk = 2;
	string message = 3;
}

// 修改用户基本信息
message UpdateUserInfoRequest {
	int64 userId = 1;
	string fullname = 2;
}

// 修改用户登录信息
message UpdateUserLoginRequest {
	int64 userId = 1;
	string username = 2;
	string password = 3;
}

// 取得用户Dashboard数据
message ComposeUserDashboardRequest {
	int64 userId = 1;
}

message ComposeUserDashboardResponse {
	int64 countServers = 1;
	int64 monthlyTrafficBytes = 2;
	int64 monthlyPeekTrafficBytes = 3;
	int64 dailyTrafficBytes = 4;
	int64 dailyPeekTrafficBytes = 5;
	repeated DailyStat dailyTrafficStats = 6;
	repeated DailyStat dailyPeekTrafficStats = 7;

	message DailyStat {
		string day = 1;
		int64 count = 2;
	}
}

// 获取用户所在的集群ID
message FindUserNodeClusterIdRequest {
	int64 userId = 1;
}

message FindUserNodeClusterIdResponse {
	int64 nodeClusterId = 1;
}

// 设置用户能使用的功能
message UpdateUserFeaturesRequest {
	int64 userId = 1;
	repeated string featureCodes = 2;
}

// 获取用户所有的功能列表
message FindUserFeaturesRequest {
	int64 userId = 1;
}

message FindUserFeaturesResponse {
	repeated UserFeature features = 1;
}

// 获取所有的功能定义
message FindAllUserFeatureDefinitionsRequest {

}

message FindAllUserFeatureDefinitionsResponse {
	repeated UserFeature features = 1;
}

// 组合看板数据
message ComposeUserGlobalBoardRequest {

}

message ComposeUserGlobalBoardResponse {
	int64 totalUsers = 1;
	int64 countTodayUsers = 2;
	int64 countWeeklyUsers = 3;
	int64 countUserNodes = 4;
	int64 countOfflineUserNodes = 5;

	repeated DailyStat dailyStats = 30;
	repeated NodeValue cpuNodeValues = 31;
	repeated NodeValue memoryNodeValues = 32;
	repeated NodeValue loadNodeValues = 33;
	repeated TrafficStat topTrafficStats = 34;

	message DailyStat {
		string day = 1;
		int64 count = 2;
	}

	message TrafficStat {
		int64 userId = 1;
		string userName = 2;
		int64 countRequests = 3;
		int64 bytes = 4;
	}
}