// Copyright 2018 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
//
//     https://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";

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

package google.showcase.v1beta1;

option go_package = "github.com/googleapis/gapic-showcase/server/genproto";
option java_package = "com.google.showcase.v1beta1";
option java_multiple_files = true;
option ruby_package = "Google::Showcase::V1beta1";

// A simple identity service.
service Identity {
  // This service is meant to only run locally on the port 7469 (keypad digits
  // for "show").
  option (google.api.default_host) = "localhost:7469";

  // Creates a user.
  rpc CreateUser(CreateUserRequest) returns (User) {
    option (google.api.http) = {
      post: "/v1beta1/users"
      body: "*"
    };
    option (google.api.method_signature) = "user.display_name,user.email";
    option (google.api.method_signature) =
        "user.display_name,user.email,user.age,user.nickname,user.enable_notifications,user.height_feet";
  }

  // Retrieves the User with the given uri.
  rpc GetUser(GetUserRequest) returns (User) {
    option (google.api.http) = {
      get: "/v1beta1/{name=users/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Updates a user.
  rpc UpdateUser(UpdateUserRequest) returns (User) {
    option (google.api.http) = {
      patch: "/v1beta1/{user.name=users/*}"
      body: "user"
    };
  }

  // Deletes a user, their profile, and all of their authored messages.
  rpc DeleteUser(DeleteUserRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1beta1/{name=users/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists all users.
  rpc ListUsers(ListUsersRequest) returns (ListUsersResponse) {
    option (google.api.http) = {
      get: "/v1beta1/users"
    };
  }
}

// A user.
message User {
  option (google.api.resource) = {
    type: "showcase.googleapis.com/User"
    pattern: "users/{user}"
  };

  // The resource name of the user.
  string name = 1;

  // The display_name of the user.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // The email address of the user.
  string email = 3 [(google.api.field_behavior) = REQUIRED];

  // The timestamp at which the user was created.
  google.protobuf.Timestamp create_time = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // The latest timestamp at which the user was updated.
  google.protobuf.Timestamp update_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // The age of the user in years.
  optional int32 age = 6;

  // The height of the user in feet.
  optional double height_feet = 7;

  // The nickname of the user.
  //
  // (-- aip.dev/not-precedent: An empty string is a valid nickname.
  //     Ordinarily, proto3_optional should not be used on a `string` field. --)
  optional string nickname = 8;

  // Enables the receiving of notifications. The default is true if unset.
  //
  // (-- aip.dev/not-precedent: The default for the feature is true.
  //     Ordinarily, the default for a `bool` field should be false. --)
  optional bool enable_notifications = 9;
}

// The request message for the google.showcase.v1beta1.Identity\CreateUser
// method.
message CreateUserRequest {
  // The user to create.
  User user = 1;
}

// The request message for the google.showcase.v1beta1.Identity\GetUser
// method.
message GetUserRequest {
  // The resource name of the requested user.
  string name = 1 [
    (google.api.resource_reference).type = "showcase.googleapis.com/User",
    (google.api.field_behavior) = REQUIRED
  ];
}

// The request message for the google.showcase.v1beta1.Identity\UpdateUser
// method.
message UpdateUserRequest {
  // The user to update.
  User user = 1;

  // The field mask to determine which fields are to be updated. If empty, the
  // server will assume all fields are to be updated.
  google.protobuf.FieldMask update_mask = 2;
}

// The request message for the google.showcase.v1beta1.Identity\DeleteUser
// method.
message DeleteUserRequest {
  // The resource name of the user to delete.
  string name = 1 [
    (google.api.resource_reference).type = "showcase.googleapis.com/User",
    (google.api.field_behavior) = REQUIRED
  ];
}

// The request message for the google.showcase.v1beta1.Identity\ListUsers
// method.
message ListUsersRequest {
  // The maximum number of users to return. Server may return fewer users
  // than requested. If unspecified, server will pick an appropriate default.
  int32 page_size = 1;

  // The value of google.showcase.v1beta1.ListUsersResponse.next_page_token
  // returned from the previous call to
  // `google.showcase.v1beta1.Identity\ListUsers` method.
  string page_token = 2;
}

// The response message for the google.showcase.v1beta1.Identity\ListUsers
// method.
message ListUsersResponse {
  // The list of users.
  repeated User users = 1;

  // A token to retrieve next page of results.
  // Pass this value in ListUsersRequest.page_token field in the subsequent
  // call to `google.showcase.v1beta1.Message\ListUsers` method to retrieve the
  // next page of results.
  string next_page_token = 2;
}
