syntax = "proto3";

package pait.api;
import "google/protobuf/descriptor.proto";

message ApiRule {

  oneof http_method {
    // Maps to HTTP GET. Used for listing and getting information about
    // resources.
    HttpMethod get = 2;

    // Maps to HTTP PUT. Used for replacing a resource.
    HttpMethod put = 3;

    // Maps to HTTP POST. Used for creating a resource or performing an action.
    HttpMethod post = 4;

    // Maps to HTTP DELETE. Used for deleting a resource.
    HttpMethod delete = 5;

    // Maps to HTTP PATCH. Used for updating a resource.
    HttpMethod patch = 6;

    // The custom pattern is used for specifying an HTTP method that is not
    // included in the `pattern` field, such as HEAD, or "*" to leave the
    // HTTP method unspecified for this rule. The wild-card rule is useful
    // for services that provide content to Web (HTML) clients.
    CustomHttpPattern custom = 8;

    // Automatically generated by gRPC Gateway
    HttpMethod any = 9;
  }

  // Note: Pait Not support
  // // The name of the request field whose value is mapped to the HTTP request
  // // body, or `*` for mapping all request fields not captured by the path
  // // pattern to the HTTP body, or omitted for not having any HTTP request body.
  // //
  // // NOTE: the referred field must be present at the top-level of the request
  // // message type.
  string body = 7;

  // Note: Pait Not support
  // // Optional. The name of the response field whose value is mapped to the HTTP
  // // response body. When omitted, the entire response message will be used
  // // as the HTTP response body.
  // //
  // // NOTE: The referred field must be present at the top-level of the response
  // // message type.
  string response_body = 12;

  // Additional HTTP bindings for the selector. Nested bindings must
  // not contain an `additional_bindings` field themselves (that is,
  // the nesting may only be one level deep).
  repeated ApiRule additional_bindings = 11;

  // the group to which the method belongs
  string group = 21;
  // The tag corresponding to this method and the description of the tag
  repeated Tag tag = 22;
  // a summary of the method
  string summary = 23;
  // documentation for the use of this method
  string desc = 24;
  // whether to map the method
  bool not_enable= 25;
  // Write the author of the API
  repeated string author = 26;

  // Specifies how to build a new Message
  BuildMessage request_message = 27;
  BuildMessage response_message = 28;
}

// A custom pattern is used for defining custom HTTP verb.
message CustomHttpPattern {
  // The name of this custom HTTP verb.
  HttpMethod kind = 1;

  // The path matched by this custom verb.
  HttpMethod path = 2;
}

message Tag {
  string name = 1;
  string  desc = 2;
}

message HttpMethod {
  oneof http_url {
    // The specified http url, if empty, it will be generated by gRPC Gateway
    // example: /api/user/create
    //          /api/user/delete
    string url = 1;
    // If the value is True, the url is the url corresponding to the rpc method
    bool default = 2;
  }
}

message BuildMessage {
  // Create a new Message from the original Message through different actions
  // Since Protobuf does not support the use of 'repeated' in 'oneof', all fields are of type 'string',
  // which are then split into arrays by specifying a delimiter when used(
  //  https://github.com/protocolbuffers/protobuf/issues/2592
  // )
  oneof action {
    // Which fields (name) in Message are not used.(A comma-separated string,e.g. "a,b" -> ["a", "b"])
    string exclude_column_name = 1;
    // Which nested field of Message to use
    //  Example:
    //    nested = "/sub/subfield"
    //    real message = SubSubMessage

    //    message GetMessageRequest {
    //      message SubSubMessage {
    //        string subfield = 1;
    //      }
    //      message SubMessage {
    //        SubSubMessage subfield = 1;
    //      }
    //      string message_id = 1;
    //      int64 revision = 2;
    //      SubMessage sub = 3;
    //    }
    string nested = 2;
  }
}

extend google.protobuf.MethodOptions {
  // design like google.api.http
  ApiRule http = 72295729;
}
