syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "gogoproto/gogo.proto";
// import "validate/validate.proto";
import "google/api/annotations.proto";
import "google/protobuf/empty.proto";

package api.v1;

option go_package = "moredoc/api/v1;v1";
option java_multiple_files = true;
option java_package = "api.v1";

// 权限
message Permission {
  int64 id = 1;           // 权限ID
  string method = 2;      // 请求方法
  string path = 3;        // 请求路径
  string title = 4;       // 权限名称
  string description = 5; // 权限描述
  google.protobuf.Timestamp created_at = 6
      [ (gogoproto.stdtime) = true ]; // 创建时间
  google.protobuf.Timestamp updated_at = 7
      [ (gogoproto.stdtime) = true ]; // 更新时间
}

// 权限请求
message GetPermissionRequest { int64 id = 1; }

// 权限响应
message GetPermissionReply { Permission permission = 1; }

// 权限列表请求
message ListPermissionRequest {
  int64 page = 1;
  int64 size = 2;
  string wd = 3;
  repeated string method = 4;
  string path = 5;
}

// 权限列表响应
message ListPermissionReply {
  int64 total = 1;
  repeated Permission permission = 2;
}

// 权限API服务
service PermissionAPI {
  // 更新权限信息。这里只能操作title和description
  rpc UpdatePermission(Permission) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      put : '/api/v1/permission',
      body : '*',
    };
  }

  // 查询权限信息
  rpc GetPermission(GetPermissionRequest) returns (Permission) {
    option (google.api.http) = {
      get : '/api/v1/permission',
    };
  }

  // 查询权限列表
  rpc ListPermission(ListPermissionRequest) returns (ListPermissionReply) {
    option (google.api.http) = {
      get : '/api/v1/permission/list',
    };
  }
}