// 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
//
//     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/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.Bigtable.Admin.V2";
option go_package = "google.golang.org/genproto/googleapis/bigtable/admin/v2;admin";
option java_multiple_files = true;
option java_outer_classname = "TableProto";
option java_package = "com.google.bigtable.admin.v2";
option php_namespace = "Google\\Cloud\\Bigtable\\Admin\\V2";

// A collection of user data indexed by row, column, and timestamp.
// Each table is served using the resources of its parent cluster.
message Table {
  // The state of a table's data in a particular cluster.
  message ClusterState {
    // Table replication states.
    enum ReplicationState {
      // The replication state of the table is unknown in this cluster.
      STATE_NOT_KNOWN = 0;

      // The cluster was recently created, and the table must finish copying
      // over pre-existing data from other clusters before it can begin
      // receiving live replication updates and serving Data API requests.
      INITIALIZING = 1;

      // The table is temporarily unable to serve Data API requests from this
      // cluster due to planned internal maintenance.
      PLANNED_MAINTENANCE = 2;

      // The table is temporarily unable to serve Data API requests from this
      // cluster due to unplanned or emergency maintenance.
      UNPLANNED_MAINTENANCE = 3;

      // The table can serve Data API requests from this cluster. Depending on
      // replication delay, reads may not immediately reflect the state of the
      // table in other clusters.
      READY = 4;
    }

    // (`OutputOnly`)
    // The state of replication for the table in this cluster.
    ReplicationState replication_state = 1;
  }

  // Possible timestamp granularities to use when keeping multiple versions
  // of data in a table.
  enum TimestampGranularity {
    // The user did not specify a granularity. Should not be returned.
    // When specified during table creation, MILLIS will be used.
    TIMESTAMP_GRANULARITY_UNSPECIFIED = 0;

    // The table keeps data versioned at a granularity of 1ms.
    MILLIS = 1;
  }

  // Defines a view over a table's fields.
  enum View {
    // Uses the default view for each method as documented in its request.
    VIEW_UNSPECIFIED = 0;

    // Only populates `name`.
    NAME_ONLY = 1;

    // Only populates `name` and fields related to the table's schema.
    SCHEMA_VIEW = 2;

    // Only populates `name` and fields related to the table's
    // replication state.
    REPLICATION_VIEW = 3;

    // Populates all fields.
    FULL = 4;
  }

  // (`OutputOnly`)
  // The unique name of the table. Values are of the form
  // `projects/<project>/instances/<instance>/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`.
  // Views: `NAME_ONLY`, `SCHEMA_VIEW`, `REPLICATION_VIEW`, `FULL`
  string name = 1;

  // (`OutputOnly`)
  // Map from cluster ID to per-cluster table state.
  // If it could not be determined whether or not the table has data in a
  // particular cluster (for example, if its zone is unavailable), then
  // there will be an entry for the cluster with UNKNOWN `replication_status`.
  // Views: `REPLICATION_VIEW`, `FULL`
  map<string, ClusterState> cluster_states = 2;

  // (`CreationOnly`)
  // The column families configured for this table, mapped by column family ID.
  // Views: `SCHEMA_VIEW`, `FULL`
  map<string, ColumnFamily> column_families = 3;

  // (`CreationOnly`)
  // The granularity (i.e. `MILLIS`) at which timestamps are stored in
  // this table. Timestamps not matching the granularity will be rejected.
  // If unspecified at creation time, the value will be set to `MILLIS`.
  // Views: `SCHEMA_VIEW`, `FULL`
  TimestampGranularity granularity = 4;
}

// A set of columns within a table which share a common configuration.
message ColumnFamily {
  // Garbage collection rule specified as a protobuf.
  // Must serialize to at most 500 bytes.
  //
  // NOTE: Garbage collection executes opportunistically in the background, and
  // so it's possible for reads to return a cell even if it matches the active
  // GC expression for its family.
  GcRule gc_rule = 1;
}

// Rule for determining which cells to delete during garbage collection.
message GcRule {
  // A GcRule which deletes cells matching all of the given rules.
  message Intersection {
    // Only delete cells which would be deleted by every element of `rules`.
    repeated GcRule rules = 1;
  }

  // A GcRule which deletes cells matching any of the given rules.
  message Union {
    // Delete cells which would be deleted by any element of `rules`.
    repeated GcRule rules = 1;
  }

  // Garbage collection rules.
  oneof rule {
    // Delete all cells in a column except the most recent N.
    int32 max_num_versions = 1;

    // Delete cells in a column older than the given age.
    // Values must be at least one millisecond, and will be truncated to
    // microsecond granularity.
    google.protobuf.Duration max_age = 2;

    // Delete cells that would be deleted by every nested rule.
    Intersection intersection = 3;

    // Delete cells that would be deleted by any nested rule.
    Union union = 4;
  }
}

// A snapshot of a table at a particular time. A snapshot can be used as a
// checkpoint for data restoration or a data source for a new table.
//
// Note: This is a private alpha release of Cloud Bigtable snapshots. This
// feature is not currently available to most Cloud Bigtable customers. This
// feature might be changed in backward-incompatible ways and is not recommended
// for production use. It is not subject to any SLA or deprecation policy.
message Snapshot {
  // Possible states of a snapshot.
  enum State {
    // The state of the snapshot could not be determined.
    STATE_NOT_KNOWN = 0;

    // The snapshot has been successfully created and can serve all requests.
    READY = 1;

    // The snapshot is currently being created, and may be destroyed if the
    // creation process encounters an error. A snapshot may not be restored to a
    // table while it is being created.
    CREATING = 2;
  }

  // (`OutputOnly`)
  // The unique name of the snapshot.
  // Values are of the form
  // `projects/<project>/instances/<instance>/clusters/<cluster>/snapshots/<snapshot>`.
  string name = 1;

  // (`OutputOnly`)
  // The source table at the time the snapshot was taken.
  Table source_table = 2;

  // (`OutputOnly`)
  // The size of the data in the source table at the time the snapshot was
  // taken. In some cases, this value may be computed asynchronously via a
  // background process and a placeholder of 0 will be used in the meantime.
  int64 data_size_bytes = 3;

  // (`OutputOnly`)
  // The time when the snapshot is created.
  google.protobuf.Timestamp create_time = 4;

  // (`OutputOnly`)
  // The time when the snapshot will be deleted. The maximum amount of time a
  // snapshot can stay active is 365 days. If 'ttl' is not specified,
  // the default maximum of 365 days will be used.
  google.protobuf.Timestamp delete_time = 5;

  // (`OutputOnly`)
  // The current state of the snapshot.
  State state = 6;

  // (`OutputOnly`)
  // Description of the snapshot.
  string description = 7;
}
