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

package pb;

import "models/model_server.proto";
import "models/model_dns_domain.proto";
import "models/model_server_name_auditing_result.proto";
import "models/rpc_messages.proto";

service ServerService {
	// 创建服务
	rpc createServer (CreateServerRequest) returns (CreateServerResponse);

	// 修改服务基本信息
	rpc updateServerBasic (UpdateServerBasicRequest) returns (RPCSuccess);

	// 修改服务是否启用
	rpc updateServerIsOn (UpdateServerIsOnRequest) returns (RPCSuccess);

	// 修改服务的HTTP设置
	rpc updateServerHTTP (UpdateServerHTTPRequest) returns (RPCSuccess);

	// 修改服务的HTTPS设置
	rpc updateServerHTTPS (UpdateServerHTTPSRequest) returns (RPCSuccess);

	// 修改服务的TCP设置
	rpc updateServerTCP (UpdateServerTCPRequest) returns (RPCSuccess);

	// 修改服务的TLS设置
	rpc updateServerTLS (UpdateServerTLSRequest) returns (RPCSuccess);

	// 修改服务的Unix设置
	rpc updateServerUnix (UpdateServerUnixRequest) returns (RPCSuccess);

	// 修改服务的UDP设置
	rpc updateServerUDP (UpdateServerUDPRequest) returns (RPCSuccess);

	// 修改服务的Web设置
	rpc updateServerWeb (UpdateServerWebRequest) returns (RPCSuccess);

	// 修改服务的反向代理设置
	rpc updateServerReverseProxy (UpdateServerReverseProxyRequest) returns (RPCSuccess);

	// 查找服务的域名设置
	rpc findServerNames (FindServerNamesRequest) returns (FindServerNamesResponse);

	// 修改服务的域名设置
	rpc updateServerNames (UpdateServerNamesRequest) returns (RPCSuccess);

	// 审核服务的域名设置
	rpc updateServerNamesAuditing (UpdateServerNamesAuditingRequest) returns (RPCSuccess);

	// 修改服务的DNS相关设置
	rpc updateServerDNS(UpdateServerDNSRequest) returns (RPCSuccess);

	// 重新生成CNAME
	rpc regenerateServerCNAME(RegenerateServerCNAMERequest) returns (RPCSuccess);

	// 计算匹配的服务数量
	rpc countAllEnabledServersMatch (CountAllEnabledServersMatchRequest) returns (RPCCountResponse);

	// 列出单页服务
	rpc listEnabledServersMatch (ListEnabledServersMatchRequest) returns (ListEnabledServersMatchResponse);

	// 禁用某服务
	rpc deleteServer (DeleteServerRequest) returns (RPCSuccess);

	// 查找单个服务
	rpc findEnabledServer (FindEnabledServerRequest) returns (FindEnabledServerResponse);

	// 查找服务配置
	rpc findEnabledServerConfig (FindEnabledServerConfigRequest) returns (FindEnabledServerConfigResponse);

	// 查找服务的服务类型
	rpc findEnabledServerType (FindEnabledServerTypeRequest) returns (FindEnabledServerTypeResponse);

	// 查找反向代理设置
	rpc findAndInitServerReverseProxyConfig (FindAndInitServerReverseProxyConfigRequest) returns (FindAndInitServerReverseProxyConfigResponse);

	// 初始化Web设置
	rpc findAndInitServerWebConfig (FindAndInitServerWebConfigRequest) returns (FindAndInitServerWebConfigResponse);

	// 计算使用某个SSL证书的服务数量
	rpc countAllEnabledServersWithSSLCertId (CountAllEnabledServersWithSSLCertIdRequest) returns (RPCCountResponse);

	// 查找使用某个SSL证书的所有服务
	rpc findAllEnabledServersWithSSLCertId (FindAllEnabledServersWithSSLCertIdRequest) returns (FindAllEnabledServersWithSSLCertIdResponse);

	// 计算运行在某个集群上的所有服务数量
	rpc countAllEnabledServersWithNodeClusterId (CountAllEnabledServersWithNodeClusterIdRequest) returns (RPCCountResponse);

	// 计算使用某个分组的服务数量
	rpc countAllEnabledServersWithServerGroupId (CountAllEnabledServersWithServerGroupIdRequest) returns (RPCCountResponse);

	// 通知更新
	rpc notifyServersChange (NotifyServersChangeRequest) returns (NotifyServersChangeResponse);

	// 取得某个集群下的所有服务相关的DNS
	rpc findAllEnabledServersDNSWithNodeClusterId (FindAllEnabledServersDNSWithNodeClusterIdRequest) returns (FindAllEnabledServersDNSWithNodeClusterIdResponse);

	// 查找单个服务的DNS信息
	rpc findEnabledServerDNS (FindEnabledServerDNSRequest) returns (FindEnabledServerDNSResponse);

	// 检查服务是否属于某个用户
	rpc checkUserServer (CheckUserServerRequest) returns (RPCSuccess);

	// 查找一个用户下的所有域名列表
	rpc findAllEnabledServerNamesWithUserId (FindAllEnabledServerNamesWithUserIdRequest) returns (FindAllEnabledServerNamesWithUserIdResponse);

	// 查找用户服务基本信息
	rpc findEnabledUserServerBasic (FindEnabledUserServerBasicRequest) returns (FindEnabledUserServerBasicResponse);

	// 修改用户服务基本信息
	rpc updateEnabledUserServerBasic (UpdateEnabledUserServerBasicRequest) returns (RPCSuccess);

	// 上传HTTP请求待统计数据
	rpc uploadServerHTTPRequestStat (UploadServerHTTPRequestStatRequest) returns (RPCSuccess);

	// 检查域名是否已经存在
	rpc checkServerNameDuplicationInNodeCluster (CheckServerNameDuplicationInNodeClusterRequest) returns (CheckServerNameDuplicationInNodeClusterResponse);

	// 查找最近访问的服务
	rpc findLatestServers (FindLatestServersRequest) returns (FindLatestServersResponse);

	// 查找某个服务附近的服务
	rpc findNearbyServers(FindNearbyServersRequest) returns (FindNearbyServersResponse);

	// 清除缓存
	rpc purgeServerCache(PurgeServerCacheRequest) returns (PurgeServerCacheResponse);

	// 查找流量限制
	rpc findEnabledServerTrafficLimit(FindEnabledServerTrafficLimitRequest) returns (FindEnabledServerTrafficLimitResponse);

	// 设置流量限制
	rpc updateServerTrafficLimit(UpdateServerTrafficLimitRequest) returns (RPCSuccess);

	// 修改服务套餐
	rpc updateServerUserPlan(UpdateServerUserPlanRequest) returns (RPCSuccess);
}

// 创建服务
message CreateServerRequest {
	int64 userId = 1;
	int64 adminId = 2;
	string type = 3;
	string name = 4;
	string description = 5;

	// 配置相关
	bytes serverNamesJON = 8;
	bytes httpJSON = 9;
	bytes httpsJSON = 10;
	bytes tcpJSON = 11;
	bytes tlsJSON = 12;
	bytes unixJSON = 13;
	bytes udpJSON = 14;
	int64 webId = 15;
	bytes reverseProxyJSON = 16;
	repeated int64 serverGroupIds = 17;
	int64 userPlanId = 18;

	int64 nodeClusterId = 30;
	bytes includeNodesJSON = 31;
	bytes excludeNodesJSON = 32;
}

message CreateServerResponse {
	int64 serverId = 1;
}

// 修改服务基本信息
message UpdateServerBasicRequest {
	int64 serverId = 1;
	string name = 2;
	string description = 3;
	int64 nodeClusterId = 4;
	bool isOn = 5;
	repeated int64 serverGroupIds = 6;
}

// 修改服务启是否启用
message UpdateServerIsOnRequest {
	int64 serverId = 1;
	bool isOn = 2;
}

// 修改服务的HTTP等设置
message UpdateServerHTTPRequest {
	int64 serverId = 1;
	bytes httpJSON = 2;
}

message UpdateServerHTTPSRequest {
	int64 serverId = 1;
	bytes httpsJSON = 2;
}

message UpdateServerTCPRequest {
	int64 serverId = 1;
	bytes tcpJSON = 2;
}

message UpdateServerTLSRequest {
	int64 serverId = 1;
	bytes tlsJSON = 2;
}

message UpdateServerUnixRequest {
	int64 serverId = 1;
	bytes unixJSON = 2;
}

message UpdateServerUDPRequest {
	int64 serverId = 1;
	bytes udpJSON = 2;
}

message UpdateServerWebRequest {
	int64 serverId = 1;
	int64 webId = 2;
}

// 修改服务的反向代理设置
message UpdateServerReverseProxyRequest {
	int64 serverId = 1;
	bytes reverseProxyJSON = 2;
}

// 查找服务的域名设置
message FindServerNamesRequest {
	int64 serverId = 1;
}

message FindServerNamesResponse {
	bytes serverNamesJSON = 1;
	bool isAuditing = 2;
	bytes auditingServerNamesJSON = 3;
	ServerNameAuditingResult auditingResult = 4;
}

// 修改服务的域名设置
message UpdateServerNamesRequest {
	int64 serverId = 1;
	bytes serverNamesJSON = 2;
}

// 审核服务的域名设置
message UpdateServerNamesAuditingRequest {
	int64 serverId = 1;
	ServerNameAuditingResult auditingResult = 2;
}

// 修改服务的DNS相关设置
message UpdateServerDNSRequest {
	int64 serverId = 1;
	bool supportCNAME = 2;
}

// 重新生成CNAME
message RegenerateServerCNAMERequest {
	int64 serverId = 1;
}

// 计算服务数量
message CountAllEnabledServersMatchRequest {
	int64 serverGroupId = 1;
	string keyword = 2;
	int64 userId = 3;
	int64 nodeClusterId = 4;
	int32 auditingFlag = 5;
	string protocolFamily = 6;
}

// 列出单页服务
message ListEnabledServersMatchRequest {
	int64 offset = 1;
	int64 size = 2;
	int64 serverGroupId = 3;
	string keyword = 4;
	int64 userId = 5;
	int64 nodeClusterId = 6;
	int32 auditingFlag = 7;
	string protocolFamily = 8;
}

message ListEnabledServersMatchResponse {
	repeated Server servers = 1;
}

// 禁用服务
message DeleteServerRequest {
	int64 serverId = 1;
}

// 查找单个服务
message FindEnabledServerRequest {
	int64 serverId = 1;
}

message FindEnabledServerResponse {
	Server server = 1;
}

// 查找服务配置
message FindEnabledServerConfigRequest {
	int64 serverId = 1;
}

message FindEnabledServerConfigResponse {
	bytes serverJSON = 1;
}

// 查找服务的服务类型
message FindEnabledServerTypeRequest {
	int64 serverId = 1;
}

message FindEnabledServerTypeResponse {
	string type = 1;
}

// 查找反向代理设置
message FindAndInitServerReverseProxyConfigRequest {
	int64 serverId = 1;
}

message FindAndInitServerReverseProxyConfigResponse {
	bytes reverseProxyJSON = 1;
	bytes reverseProxyRefJSON = 2;
}

// 初始化Web设置
message FindAndInitServerWebConfigRequest {
	int64 serverId = 1;
}

message FindAndInitServerWebConfigResponse {
	bytes webJSON = 1;
}

// 计算使用某个SSL证书的服务数量
message CountAllEnabledServersWithSSLCertIdRequest {
	int64 sslCertId = 1;
}

// 查找使用某个SSL证书的所有服务
message FindAllEnabledServersWithSSLCertIdRequest {
	int64 sslCertId = 1;
}

message FindAllEnabledServersWithSSLCertIdResponse {
	repeated Server servers = 1;
}

// 计算运行在某个集群上的所有服务数量
message CountAllEnabledServersWithNodeClusterIdRequest {
	int64 nodeClusterId = 1;
}

// 计算使用某个分组的服务数量
message CountAllEnabledServersWithServerGroupIdRequest {
	int64 serverGroupId = 1;
}

// 通知更新
message NotifyServersChangeRequest {

}

message NotifyServersChangeResponse {

}

// 取得某个集群下的所有服务相关的DNS
message FindAllEnabledServersDNSWithNodeClusterIdRequest {
	int64 nodeClusterId = 1;
}

message FindAllEnabledServersDNSWithNodeClusterIdResponse {
	repeated ServerDNSInfo servers = 1;
}

message ServerDNSInfo {
	int64 id = 1;
	string name = 2;
	string dnsName = 3;
}

// 查找单个服务的DNS信息
message FindEnabledServerDNSRequest {
	int64 serverId = 1;
}

message FindEnabledServerDNSResponse {
	string dnsName = 1;
	DNSDomain domain = 2;
	bool supportCNAME = 3;
}

// 检查服务是否属于某个用户
message CheckUserServerRequest {
	int64 serverId = 1;
}

// 查找一个用户下的所有域名列表
message FindAllEnabledServerNamesWithUserIdRequest {
	int64 userId = 1;
}

message FindAllEnabledServerNamesWithUserIdResponse {
	repeated string serverNames = 1;
}

// 查找用户服务基本信息
message FindEnabledUserServerBasicRequest {
	int64 serverId = 1;
}

message FindEnabledUserServerBasicResponse {
	Server server = 1;
}

// 修改用户服务基本信息
message UpdateEnabledUserServerBasicRequest {
	int64 serverId = 1;
	string name = 2;
}

// 上传HTTP请求待统计数据
message UploadServerHTTPRequestStatRequest {
	string month = 1;
	string day = 2;
	repeated RegionCity regionCities = 3;
	repeated RegionProvider regionProviders = 4;
	repeated System systems = 5;
	repeated Browser browsers = 6;
	repeated HTTPFirewallRuleGroup httpFirewallRuleGroups = 7;

	message RegionCity {
		int64 serverId = 1;
		string countryName = 2;
		string provinceName = 3;
		string cityName = 4;
		int64 count = 5;
	}

	message RegionProvider {
		int64 serverId = 1;
		string name = 2;
		int64 count = 3;
	}

	message System {
		int64 serverId = 1;
		string name = 2;
		string version = 3;
		int64 count = 4;
	}

	message Browser {
		int64 serverId = 1;
		string name = 2;
		string version = 3;
		int64 count = 4;
	}

	message HTTPFirewallRuleGroup {
		int64 serverId = 1;
		int64 httpFirewallRuleGroupId = 2;
		string action = 3;
		int64 count = 4;
	}
}

// 检查域名是否已经存在
message CheckServerNameDuplicationInNodeClusterRequest {
	int64 nodeClusterId = 1;
	repeated string serverNames = 2; // 可以同时检查一批域名
	int64 excludeServerId = 3; // 要排除的服务ID
}

message CheckServerNameDuplicationInNodeClusterResponse {
	repeated string duplicatedServerNames = 1;
}

// 查找最近访问的服务
message FindLatestServersRequest {
	int64 size = 1;
}

message FindLatestServersResponse {
	repeated Server servers = 1;
}

// 查找某个服务附近的服务
message FindNearbyServersRequest {
	int64 serverId = 1;
}

message FindNearbyServersResponse {
	string scope = 1; // 范围 cluster|group
	repeated GroupInfo groups = 2;

	message GroupInfo {
		string name = 1;
		repeated Server servers = 2;
	}
}

// 清除缓存
message PurgeServerCacheRequest {
	repeated string domains = 1;
	repeated string keys = 2;
	repeated string prefixes = 3;
}

message PurgeServerCacheResponse {
	bool isOk = 1;
	string message = 2;
}

// 查找流量限制
message FindEnabledServerTrafficLimitRequest {
	int64 serverId = 1;
}

message FindEnabledServerTrafficLimitResponse {
	bytes trafficLimitJSON = 1;
}

// 设置流量限制
message UpdateServerTrafficLimitRequest {
	int64 serverId = 1;
	bytes trafficLimitJSON = 2;
}

// 修改服务套餐
message UpdateServerUserPlanRequest {
	int64 serverId = 1;
	int64 userPlanId = 2;
}