// Copyright 2016 Google Inc. All Rights Reserved.
//
// 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";

option java_multiple_files = true;
option java_package = "com.google.trillian.proto";
option java_outer_classname = "TrillianAdminApiProto";
option go_package = "github.com/google/trillian";

package trillian;

import "trillian.proto";
import "crypto/keyspb/keyspb.proto";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/empty.proto";

// ListTrees request.
// No filters or pagination options are provided.
message ListTreesRequest {}

// ListTrees response.
// No pagination is provided, all trees the requester has access to are
// returned.
message ListTreesResponse {
  // Trees matching the list request filters.
  repeated Tree tree = 1;
}

// GetTree request.
message GetTreeRequest {
  // ID of the tree to retrieve.
  int64 tree_id = 1;
}

// CreateTree request.
message CreateTreeRequest {
  // Tree to be created. See Tree and CreateTree for more details.
  Tree tree = 1;

  // Describes how the tree's private key should be generated.
  // Only needs to be set if tree.private_key is not set.
  keyspb.Specification key_spec = 2;
}

// UpdateTree request.
message UpdateTreeRequest {
  // Tree to be updated.
  Tree tree = 1;

  // Fields modified by the update request.
  // For example: "tree_state", "display_name", "description".
  google.protobuf.FieldMask update_mask = 2;
}

// DeleteTree request.
message DeleteTreeRequest {
  // ID of the tree to delete.
  int64 tree_id = 1;
}

// Trillian Administrative interface.
// Allows creation and management of Trillian trees (both log and map trees).
service TrillianAdmin {
  // Lists all trees the requester has access to.
  rpc ListTrees(ListTreesRequest) returns(ListTreesResponse) {}

  // Retrieves a tree by ID.
  rpc GetTree(GetTreeRequest) returns(Tree) {
    option (google.api.http) = {
      get: "/v1beta1/trees/{tree_id=*}"
    };
  }

  // Creates a new tree.
  // System-generated fields are not required and will be ignored if present,
  // e.g.: tree_id, create_time and update_time.
  // Returns the created tree, with all system-generated fields assigned.
  rpc CreateTree(CreateTreeRequest) returns(Tree) {
    option (google.api.http) = {
      post: "/v1beta1/trees"
      body: "*"
    };
  }

  // Updates a tree.
  // See Tree for details. Readonly fields cannot be updated.
  rpc UpdateTree(UpdateTreeRequest) returns(Tree) {
    option (google.api.http) = {
      patch: "/v1beta1/trees/{tree.tree_id=*}"
      body: "*"
    };
  }

  // Soft-deletes a tree.
  // A soft-deleted tree may be undeleted for a certain period, after which
  // it'll be permanently deleted.
  // TODO(codingllama): Provide an undelete RPC.
  rpc DeleteTree(DeleteTreeRequest) returns(google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1beta1/trees/{tree_id=*}"
    };
  }
}
