syntax = "proto3";

message DepartmentInfo {
  int64 ID = 1;
  string status = 2;
  string created_at = 3;
  string updated_at = 4;
  string name = 5;
  int64 leader_id = 6;
  string remark = 7;
  int64 parent_id = 8;

  // relations
  DepartmentInfo parent = 10;
  repeated DepartmentInfo children = 11;
  repeated UserInfo users = 12;
  UserInfo leader = 13;
}

message DepartmentReq {
  int64 ID = 1; // 通过ID查询
  string name = 2; // 通过Name like查询
  int64 leader_id = 3; // 通过负责人查询
  int64 parent_id = 4; // 通过父节点查询

  bool with_leader = 5; // 查询leader信息
  bool with_user = 6; // 查询用户信息
  bool with_children = 7; // 查询子节点信息

  optional Pagination page = 10;
}

message DepartmentListResp {
  optional Pagination page = 1;
  repeated DepartmentInfo data = 2;
}

service Core {
  // Role management
  // group: department
  rpc createDepartment (DepartmentInfo) returns (BaseIDResp);
  // group: department
  rpc updateDepartment (DepartmentInfo) returns (BaseResp);
  // group: department
  rpc getDepartmentList (DepartmentReq) returns (DepartmentListResp);
  // group: department
  rpc getDepartment (DepartmentReq) returns (DepartmentInfo);
  // group: department
  rpc deleteDepartment (IDsReq) returns (BaseResp);
}