// Copyright 2016 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 google.bigtable.admin.v2;

import "google/api/annotations.proto";
import "google/bigtable/admin/v2/table.proto";
import "google/protobuf/empty.proto";

option java_multiple_files = true;
option java_outer_classname = "BigtableTableAdminProto";
option java_package = "com.google.bigtable.admin.v2";


// Service for creating, configuring, and deleting Cloud Bigtable tables.
// Provides access to the table schemas only, not the data stored within
// the tables.
service BigtableTableAdmin {
  // Creates a new table in the specified instance.
  // The table can be created with a full set of initial column families,
  // specified in the request.
  rpc CreateTable(CreateTableRequest) returns (Table) {
    option (google.api.http) = { post: "/v2/{parent=projects/*/instances/*}/tables" body: "*" };
  }

  // Lists all tables served from a specified instance.
  rpc ListTables(ListTablesRequest) returns (ListTablesResponse) {
    option (google.api.http) = { get: "/v2/{parent=projects/*/instances/*}/tables" };
  }

  // Gets metadata information about the specified table.
  rpc GetTable(GetTableRequest) returns (Table) {
    option (google.api.http) = { get: "/v2/{name=projects/*/instances/*/tables/*}" };
  }

  // Permanently deletes a specified table and all of its data.
  rpc DeleteTable(DeleteTableRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = { delete: "/v2/{name=projects/*/instances/*/tables/*}" };
  }

  // Atomically performs a series of column family modifications
  // on the specified table.
  rpc ModifyColumnFamilies(ModifyColumnFamiliesRequest) returns (Table) {
    option (google.api.http) = { post: "/v2/{name=projects/*/instances/*/tables/*}:modifyColumnFamilies" body: "*" };
  }

  // Permanently drop/delete a row range from a specified table. The request can
  // specify whether to delete all rows in a table, or only those that match a
  // particular prefix.
  rpc DropRowRange(DropRowRangeRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = { post: "/v2/{name=projects/*/instances/*/tables/*}:dropRowRange" body: "*" };
  }
}

// Request message for [google.bigtable.admin.v2.BigtableTableAdmin.CreateTable][google.bigtable.admin.v2.BigtableTableAdmin.CreateTable]
message CreateTableRequest {
  // An initial split point for a newly created table.
  message Split {
    // Row key to use as an initial tablet boundary.
    bytes key = 1;
  }

  // The unique name of the instance in which to create the table.
  // Values are of the form projects/<project>/instances/<instance>
  string parent = 1;

  // The name by which the new table should be referred to within the parent
  // instance, e.g. "foobar" rather than "<parent>/tables/foobar".
  string table_id = 2;

  // The Table to create.
  Table table = 3;

  // The optional list of row keys that will be used to initially split the
  // table into several tablets (Tablets are similar to HBase regions).
  // Given two split keys, "s1" and "s2", three tablets will be created,
  // spanning the key ranges: [, s1), [s1, s2), [s2, ).
  //
  // Example:
  //  * Row keys := ["a", "apple", "custom", "customer_1", "customer_2",
  //                 "other", "zz"]
  //  * initial_split_keys := ["apple", "customer_1", "customer_2", "other"]
  //  * Key assignment:
  //    - Tablet 1 [, apple)                => {"a"}.
  //    - Tablet 2 [apple, customer_1)      => {"apple", "custom"}.
  //    - Tablet 3 [customer_1, customer_2) => {"customer_1"}.
  //    - Tablet 4 [customer_2, other)      => {"customer_2"}.
  //    - Tablet 5 [other, )                => {"other", "zz"}.
  repeated Split initial_splits = 4;
}

// Request message for [google.bigtable.admin.v2.BigtableTableAdmin.DropRowRange][google.bigtable.admin.v2.BigtableTableAdmin.DropRowRange]
message DropRowRangeRequest {
  // The unique name of the table on which to drop a range of rows.
  // Values are of the form projects/<project>/instances/<instance>/tables/<table>
  string name = 1;

  oneof target {
    // Delete all rows that start with this row key prefix. Prefix cannot be
    // zero length.
    bytes row_key_prefix = 2;

    // Delete all rows in the table. Setting this to false is a no-op.
    bool delete_all_data_from_table = 3;
  }
}

// Request message for [google.bigtable.admin.v2.BigtableTableAdmin.ListTables][google.bigtable.admin.v2.BigtableTableAdmin.ListTables]
message ListTablesRequest {
  // The unique name of the instance for which tables should be listed.
  // Values are of the form projects/<project>/instances/<instance>
  string parent = 1;

  // The view to be applied to the returned tables' fields.
  // Defaults to NAME_ONLY if unspecified (no others are currently supported).
  Table.View view = 2;

  // The value of `next_page_token` returned by a previous call.
  string page_token = 3;
}

// Response message for [google.bigtable.admin.v2.BigtableTableAdmin.ListTables][google.bigtable.admin.v2.BigtableTableAdmin.ListTables]
message ListTablesResponse {
  // The tables present in the requested cluster.
  repeated Table tables = 1;

  // Set if not all tables could be returned in a single response.
  // Pass this value to `page_token` in another request to get the next
  // page of results.
  string next_page_token = 2;
}

// Request message for [google.bigtable.admin.v2.BigtableTableAdmin.GetTable][google.bigtable.admin.v2.BigtableTableAdmin.GetTable]
message GetTableRequest {
  // The unique name of the requested table.
  // Values are of the form projects/<project>/instances/<instance>/tables/<table>
  string name = 1;

  // The view to be applied to the returned table's fields.
  // Defaults to SCHEMA_ONLY if unspecified.
  Table.View view = 2;
}

// Request message for [google.bigtable.admin.v2.BigtableTableAdmin.DeleteTable][google.bigtable.admin.v2.BigtableTableAdmin.DeleteTable]
message DeleteTableRequest {
  // The unique name of the table to be deleted.
  // Values are of the form projects/<project>/instances/<instance>/tables/<table>
  string name = 1;
}

// Request message for [google.bigtable.admin.v2.BigtableTableAdmin.ModifyColumnFamilies][google.bigtable.admin.v2.BigtableTableAdmin.ModifyColumnFamilies]
message ModifyColumnFamiliesRequest {
  // A create, update, or delete of a particular column family.
  message Modification {
    // The ID of the column family to be modified.
    string id = 1;

    oneof mod {
      // Create a new column family with the specified schema, or fail if
      // one already exists with the given ID.
      ColumnFamily create = 2;

      // Update an existing column family to the specified schema, or fail
      // if no column family exists with the given ID.
      ColumnFamily update = 3;

      // Drop (delete) the column family with the given ID, or fail if no such
      // family exists.
      bool drop = 4;
    }
  }

  // The unique name of the table whose families should be modified.
  // Values are of the form projects/<project>/instances/<instance>/tables/<table>
  string name = 1;

  // Modifications to be atomically applied to the specified table's families.
  // Entries are applied in order, meaning that earlier modifications can be
  // masked by later ones (in the case of repeated updates to the same family,
  // for example).
  repeated Modification modifications = 2;
}
