// -*- coding: utf-8 -*-
// Copyright 2021 Google LLC

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


syntax = "proto3";

package animalia.mollusca.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/wrappers.proto";

service Snippets {
  option (google.api.default_host) = "mollusca.example.com";

  rpc MethodOneSignature(SignatureRequest) returns(Response) {
    option (google.api.method_signature) = "my_string,my_int,my_bool";
  }

  rpc MethodLroSignatures(SignatureRequest) returns(google.longrunning.Operation) {
    option (google.api.method_signature) = "my_string,my_int,my_bool";
    option (google.longrunning.operation_info) = {
      response_type: "LroResponse"
      metadata_type: "LroMetadata"
    };
  }

  rpc ListResources(ListResourcesRequest) returns (ListResourcesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=items/*}/resources"
    };
    option (google.api.method_signature) = "parent";
  }

  rpc MethodServerStreaming(SignatureRequest) returns(stream Response) {
    option (google.api.method_signature) = "my_string,my_int,my_bool";
    option (google.api.method_signature) = "";
  }

  rpc MethodBidiStreaming(stream SignatureRequestOneRequiredField) returns (stream Response);

  rpc OneOfMethod(OneOfRequest) returns (Response);

  rpc OneOfMethodRequiredField(OneOfRequestWithRequiredField) returns (Response);
}

enum Enum {
  DEFAULT = 0; // First value must be 0 and is the default
}

message ListResourcesRequest {
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "snippets.example.com/Resource"
    }];
  
  string resource_with_wildcard = 2 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "snippets.example.com/ResourceWithWildcardSegment"
    }];

  int32 page_size = 3;
  string page_token = 4;
}

message ListResourcesResponse {
  repeated Resource resources = 1;
  string next_page_token = 2;
}

message ParentResource {
  option (google.api.resource) = {
    type: "snippets.example.com/ParentResource"
    pattern: "items/{item_id}"
  };
  string name = 1;
}

message Resource {
  option (google.api.resource) = {
    type: "snippets.example.com/Resource"
    pattern: "items/{item_id}/parts/{part_id}"
  };
  string name = 1;
}

message ResourceWithWildcardSegment {
  option (google.api.resource) = {
    type: "snippets.example.com/ResourceWithWildcardSegment"
    pattern: "items/{item_id}/parts/{part_id=**}"
  };
  string name = 1;
}


message MessageWithNesting {
  message NestedMessage {
    string required_string = 1 [(google.api.field_behavior) = REQUIRED];
    string optional_string = 2;
  }

  NestedMessage message = 1 [(google.api.field_behavior) = REQUIRED];
  int32 my_int = 2 [(google.api.field_behavior) = REQUIRED];
}


message SignatureRequestOneRequiredField {
  string my_string = 1 [(google.api.field_behavior) = REQUIRED];
}

message SignatureRequest {
  string my_string = 1 [(google.api.field_behavior) = REQUIRED];
  int32 my_int = 2 [(google.api.field_behavior) = REQUIRED];
  bool my_bool = 3 [(google.api.field_behavior) = REQUIRED];
  map<int32, string> map_int_string = 4;
  MessageWithNesting my_message = 5 [(google.api.field_behavior) = REQUIRED];
  Enum single_enum = 6 [(google.api.field_behavior) = REQUIRED];
}


message Response {
}

message LroResponse {
}

message LroMetadata {
}

message OneOfRequest {
  string non_one_of_string = 1 [(google.api.field_behavior) = REQUIRED];
  oneof my_one_of {
    string my_string = 2;
    int32 my_number = 3;
  }
}


message OneOfRequestWithRequiredField {
  string non_one_of_string = 1 [(google.api.field_behavior) = REQUIRED];

  // Some APIs mark every field in a "required" oneof as required
  oneof my_one_of {
    string my_string = 2 [(google.api.field_behavior) = REQUIRED];
    int32 my_number = 3 [(google.api.field_behavior) = REQUIRED];
  }
}