syntax = "proto3";

option csharp_namespace = "DBDevelopService";

package dbDevelopService;

// The greeting service definition.
service DevelopServer {

  //Login
  rpc Login(LoginRequest) returns (LoginReply);

  //
  rpc IsAdmin(GetRequest) returns (BoolResultReplay);

    //
  rpc CanNewDatabase(GetRequest) returns (BoolResultReplay);


  //数据库开发服务权限操纵
  //新建用户
  rpc NewUser(NewUserRequest) returns (BoolResultReplay);

  //修改当前用户密码
  rpc ModifyPassword(ModifyPasswordRequest) returns (BoolResultReplay);

  rpc ReNameUser(ReNameUserRequest) returns (BoolResultReplay);

  //修改用户信息
  rpc UpdateUser(UpdateUserRequest) returns (BoolResultReplay);

    //更新用户密码
  rpc UpdateUserPassword(UpdatePasswordRequest) returns (BoolResultReplay);

  //删除用户
  rpc RemoveUser(RemoveUserRequest) returns (BoolResultReplay);

  //获取开发者用户
  rpc GetUsers(GetRequest) returns (GetUsersReplay);

  //枚举权限列表
 // rpc GetPermissions(GetRequest) returns (GetPermissionsReplay);

  //数据库操作
  //枚举检索数据库
  rpc QueryDatabase(QueryDatabaseRequest) returns (QueryDatabaseReplay);

  //新建数据库
  rpc NewDatabase(NewDatabaseRequest) returns (BoolResultReplay);

  //数据库权限操作
  //新建数据库用户
  rpc NewDatabaseUser(NewDatabaseUserRequest) returns (BoolResultReplay);

  //修改数据库用户密码
  rpc ModifyDatabaseUserPassword(ModifyDatabaseUserPasswordRequest) returns (BoolResultReplay);

  //更新数据库用户信息
  rpc UpdateDatabaseUser(UpdateDatabaseUserRequest) returns (BoolResultReplay);

  //删除数据库用户
  rpc RemoveDatabaseUser(RemoveByNameRequest) returns (BoolResultReplay);

  //添加用户组
  rpc AddDatabaseUserGroup(AddGroupRequest) returns (BoolResultReplay);

  //获取用户组
  rpc GetDatabaseUserGroup(GetRequest) returns (GetGroupMessageReply);

  //删除用户组
  rpc RemoveDatabaseUserGroup(RemoveGroupRequest) returns (BoolResultReplay);

  //改名用户组
  rpc RenameDatabaseUserGroup(RenameGroupRequest) returns (BoolResultReplay);

  //移动组
  rpc MoveDatabaseUserGroup(MoveGroupRequest) returns (BoolResultReplay);

  //通过组获取用户
  rpc GetDatabaseUserByGroup(GetDatabaseUserByGroupRequest) returns (GetDatabaseUsersReplay);

  //添加数据库权限
  rpc NewDatabasePermission(DatabasePermissionRequest) returns (BoolResultReplay);


  //更新数据库权限
  rpc UpdateDatabasePermission(DatabasePermissionRequest) returns (BoolResultReplay);

  //获取数据权限列表
  rpc GetAllDatabasePermission(GetAllDatabasePermissionRequest) returns (GetAllDatabasePermissionReplay);

  //删除数据库权限
  rpc RemoveDatabasePermission(RemoveDatabasePermissionRequest) returns (BoolResultReplay);
  
  //变量操作
  //添加
  rpc AddTag(AddTagRequestMessage) returns (AddTagReplyMessage);

    //导入变量
  rpc Import(ImportTagRequestMessage) returns (ImportTagRequestReplyMessage);

  //删除
  rpc RemoveTag(RemoveTagMessageRequest) returns (BoolResultReplay);

    //删除变量历史配置
  rpc RemoveHisTag(RemoveTagMessageRequest) returns (BoolResultReplay);


  //批量删除变量
  rpc ClearTag(ClearTagRequestMessage) returns (BoolResultReplay);

  //清空整个数据库
  rpc ClearAllTag(GetRequest) returns (BoolResultReplay);

    //修改实时变量
  rpc UpdateRealTag(UpdateRealTagRequestMessage) returns (BoolResultReplay);

  //修改历史变量
  rpc UpdateHisTag(UpdateHisTagRequestMessage) returns (BoolResultReplay);


    //根据组获取变量
  rpc GetTagByGroup(GetTagByGroupRequest) returns (GetTagMessageReply);

  //获取所有变量
  rpc GetAllTag(GetTagByGroupRequest) returns (GetTagMessageReply);


  //获取所有历史变量
  rpc GetHisAllTag(GetRequest) returns (GetHistTagMessageReply);

  //查询指定条件的变量
  rpc QueryRealTag(QueryMessageRequest) returns (GetRealTagMessageReply);

  //查询历史变量
  rpc QueryHisTag(QueryMessageRequest) returns (GetHistTagMessageReply);


  //获取所有实时变量
  rpc GetRealAllTag(GetRequest) returns (GetRealTagMessageReply);


  //变量组操作
  //获取变量组
  rpc GetTagGroup(GetRequest) returns (GetTagGroupMessageReply);

  //添加变量组
  rpc AddTagGroup(AddGroupRequest) returns (AddGroupReplay);

  //粘贴组
  rpc PasteTagGroup(PasteGroupRequest) returns (PasteGroupReplay);

  //删除变量组
  rpc RemoveTagGroup(RemoveGroupRequest) returns (BoolResultReplay);

  //重命名变量组
  rpc RenameTagGroup(RenameGroupRequest) returns (BoolResultReplay);

  //移动变量组
  rpc MoveTagGroup(MoveGroupRequest) returns (BoolResultReplay);



  //保存
  rpc Save(GetRequest) returns (BoolResultReplay);

  //撤销
  rpc Cancel(GetRequest) returns (BoolResultReplay);

    //数据库是否变脏
  rpc IsDatabaseDirty(DatabasesRequest) returns (BoolResultReplay);

  //获取驱动列表
  rpc GetRegisteDrivers(GetRequest) returns (GetRegisteDriversReplay);

  //Logout
   rpc Logout(LogoutRequest) returns (BoolResultReplay);

   //启动数据库
   rpc Start(DatabasesRequest) returns (BoolResultReplay);

   //停止数据库
   rpc Stop(DatabasesRequest) returns (BoolResultReplay);

   //在运行不中断的情况下加载数据库
   rpc ReRun(DatabasesRequest) returns (BoolResultReplay);

   rpc IsDatabaseRunning(DatabasesRequest) returns (BoolResultReplay);

}

//获取驱动列表返回消息
message GetRegisteDriversReplay
{
    bool Result =1;
    string ErroMessage=2;
    repeated Driver Drivers=3;
}

message Driver
{
    string Name=1;
    repeated string Registors=2;
}

//获取数据权限列表
message GetAllDatabasePermissionRequest
{
    string LoginId=1;
    string Database=2;
}

//
message GetAllDatabasePermissionReplay
{
    bool Result =1;
    string ErroMessage=2;
    repeated DatabasePermission Permission=3;
}


message RemoveDatabasePermissionRequest
{
    string LoginId=1;
    string Database=2;
    string Permission=3;
}

//
message DatabasePermissionRequest
{
    string LoginId=1;
    string Database=2;
    DatabasePermission Permission=3;
}

//
message DatabasePermission
{
    string Name=1;
    string Desc=2;
    bool EnableWrite=3;
    bool SuperPermission=4;
    repeated string Group=5;
}

//新建数据库用户
message NewDatabaseUserRequest
{
    string LoginId=1;
    string Database=2;
    string userName=3;
    string password=4;
       string Group=5;
    repeated string permission=6;
}

//更新数据库用户密码
message ModifyDatabaseUserPasswordRequest
{
    string loginId=1;
    string Database=2;
    string userName=3;
    string password=4;
}

//修改数据库用户信息
message UpdateDatabaseUserRequest
{
    string loginId=1;
     string Database=2;
    string userName=3;
    string Group=4;
    repeated string permission=5;

}

message ReNameUserRequest
{
   string loginId =1;
   string OldName=2;
   string NewName=3;
}

//新建用户
message NewUserRequest
{
   string loginId =1;
   string userName=2;
   string password=3;
   bool IsAdmin=4;
   bool NewDatabasePermission=5;
   repeated string Database=6;
}

//更新用户密码
message ModifyPasswordRequest
{
    string loginId=1;
    string userName=2;
    string password=3;
    string newpassword=4;
}

//修改用户信息
message UpdateUserRequest
{
    string loginId=1;
    string userName=2;
    bool IsAdmin=3;
    bool NewDatabasePermission=4;
    repeated string Database=5;
}

message RemoveUserRequest
{
    string loginId=1;
    string userName=2;
}

//更新用户密码
message UpdatePasswordRequest
{
    string loginId=1;
    string userName=2;
    string password=3;
}

message GetPermissionsReplay
{
    bool Result =1;
    repeated string Permission=2;
}

///
message GetDatabaseUserByGroupRequest
{
    string LoginId=1;
    string Database=2;
    string Group=3;
}

//
message GetDatabaseUsersReplay
{
    bool Result =1;
    string ErroMessage=2;
   repeated DatabaseUserMessage Users=3;
}

//数据库用户信息
message DatabaseUserMessage
{
    string userName=1;
    string Group=2;
    repeated string permission=3;
}

message GetUsersReplay
{
    bool Result =1;
    string ErroMessage=2;
   repeated UserMessage Users=3;
}

message UserMessage
{
    string userName=1;
    bool IsAdmin=2;
    bool NewDatabase=3;
    repeated string Databases=4;
}

message NewDatabaseRequest
{
    string loginId =1;
    string Database=2;
    string Desc=3;
}


message DatabasesRequest
{
    string loginId=1;
    string Database=2;
}

message QueryDatabaseRequest
{
   string loginId =1;
}

message QueryDatabaseReplay
{
    bool Result =1;
    string ErroMessage=2;
   repeated KeyValueMessage Database=3;
}

message LoginRequest
{
    string userName=1;
    string password=2;
}

message LoginReply
{
    string loginId=1;
}

message LogoutRequest
{
    string LoginId=1;
}

//
message AddTagRequestMessage
{
    string loginId =1;
     string Database=2;
    RealTagMessage realTag = 3;
    HisTagMessage hisTag = 4;
}

//
message AddTagReplyMessage
{
    int32 TagId = 1;
    bool Result =2;
    string ErroMessage=3;
}


message ImportTagRequestMessage
{
    string loginId=1;
    string Database=2;
     RealTagMessage realTag = 3;
    HisTagMessage hisTag = 4;
    int32 Mode=5;
}


message ImportTagRequestReplyMessage
{
    int32 TagId = 1;
    bool Result =2;
    string ErroMessage=3;
}

message UpdateRealTagRequestMessage
{
    string loginId=1;
    string Database=2;
    RealTagMessage tag = 3;
}

message UpdateHisTagRequestMessage
{
    string loginId=1;
    string Database=2;
    HisTagMessage tag = 3;
}

//复制组
message PasteGroupRequest
{
    string LoginId=1;
    string Database=2;
    string GroupFullName=3;
    string TargetParentName=4;
}

message PasteGroupReplay
{
    bool Result =1;
    string ErroMessage=2;
    string Group=3;
}

//添加组
message AddGroupRequest
{
    string LoginId=1;
    string Database=2;
    string Name=3;
    string ParentName=4;
}

message AddGroupReplay
{
    bool Result =1;
    string ErroMessage=2;
    string Group=3;
}

//通过名称删除用户
message RemoveByNameRequest
{
    string LoginId=1;
    string Database=2;
    string Name=3;
}

//删除组
message RemoveGroupRequest
{
    string LoginId=1;
    string Database=2;
    string Name=3;
}

//
message RenameGroupRequest
{
    string LoginId=1;
    string Database=2;
    string OldFullName=3;
    string NewName=4;
}

//
message MoveGroupRequest
{
    string LoginId=1;
    string Database=2;
    string Name=3;
    string OldParentName=4;
    string NewParentName=5;
}

message ClearTagRequestMessage
{
    string LoginId=1;
    string Database=2;
    string GroupFullName=3;
}


message RemoveTagMessageRequest
{
    string LoginId=1;
     string Database=2;
    repeated int32 TagId=3;
}

//
message QueryMessageRequest
{
    string LoginId=1;
    string Database=2;
    repeated KeyValueMessage conditions=3;
}

//
message KeyValueMessage
{
    string key=1;
    string value=2;
}

//
message GetRequest
{
    string LoginId=1;
    string Database=2;
}

message GetTagByGroupRequest
{
    string LoginId=1;
    string Database=2;
    string Group=3;
    int32 Index=4;
    repeated FilterMessageItem Filters=5;
}

message FilterMessageItem
{
    string key=1;
    string value=2;
}

//
message BoolResultReplay
{
    bool Result =1;
    string ErroMessage=2;
}



//获取变量配置
message GetTagMessageReply
{
    bool Result =1;
    string ErroMessage=2;
    int32 Count=3;
    int32 Index=4;
    int32 TagCount=5;
    repeated RealTagMessage realTag=6;
    repeated HisTagMessage hisTag=7;
}

message GetRealTagMessageReply
{
    bool Result =1;
    string ErroMessage=2;
    repeated RealTagMessage messages=3;
}


message GetTagGroupMessageReply
{
    bool Result =1;
    string ErroMessage=2;
    repeated TagGroup Group=3;
}

message GetGroupMessageReply
{
    bool Result =1;
    string ErroMessage=2;
    repeated Group Group=3;
}

message GetHistTagMessageReply
{
    bool Result =1;
    string ErroMessage=2;
    repeated HisTagMessage messages=3;
}


//实时变量配置
message RealTagMessage
{
  int32 Id=1;
  uint32 TagType=2;
  string Name = 3;
  string Group = 4;
  string Desc = 5;
  string LinkAddress = 6;
  string Convert=7;
  int32 ReadWriteMode=8;
  double MaxValue=9;
  double MinValue=10;
  int32 Precision=11;
}

//历史变量定义
message HisTagMessage
{
 int32 Id=1;
 uint32 Type=2;
 uint32 TagType=3;
 uint32 CompressType=4;
 uint64 Circle=5;
 repeated hisTagParameterItem Parameter=6;
}

message hisTagParameterItem
{
    string Name=1;
    double value=2;
}

//变量组
message TagGroup
{
    string Name=1;
    string Parent=2;
}

message Group
{
    string Name=1;
    string Parent=2;
}
