// Copyright 2020 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.cloud.bigquery.storage.v1alpha2;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/bigquery/storage/v1alpha2/table.proto";
import "google/protobuf/timestamp.proto";

option go_package = "google.golang.org/genproto/googleapis/cloud/bigquery/storage/v1alpha2;storage";
option java_package = "com.google.cloud.bigquery.storage.v1alpha2";
option (google.api.resource_definition) = {
  type: "bigquerystorage.googleapis.com/Table"
  pattern: "projects/{project}/datasets/{dataset}/tables/{table}"
};

// Information about a single stream that gets data inside the storage system.
message WriteStream {
  option (google.api.resource) = {
    type: "bigquerystorage.googleapis.com/WriteStream"
    pattern: "projects/{project}/datasets/{dataset}/tables/{table}/streams/{stream}"
  };

  enum Type {
    // Unknown type.
    TYPE_UNSPECIFIED = 0;

    // Data will commit automatically and appear as soon as the write is
    // acknowledged.
    COMMITTED = 1;

    // Data is invisible until the stream is committed.
    PENDING = 2;

    // Data is only visible up to the offset to which it was flushed.
    BUFFERED = 3;
  }

  // Output only. Name of the stream, in the form
  // `projects/{project}/datasets/{dataset}/tables/{table}/streams/{stream}`.
  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  Type type = 2 [(google.api.field_behavior) = IMMUTABLE];

  // Output only. Create time of the stream.
  google.protobuf.Timestamp create_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Commit time of the stream.
  // If a stream is of `COMMITTED` type, then it will have a commit_time same as
  // `create_time`. If the stream is of `PENDING` type, commit_time being empty
  // means it is not committed.
  google.protobuf.Timestamp commit_time = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The schema of the destination table. It is only returned in
  // `CreateWriteStream` response. Caller should generate data that's
  // compatible with this schema to send in initial `AppendRowsRequest`.
  // The table schema could go out of date during the life time of the stream.
  TableSchema table_schema = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Id set by client to annotate its identity.
  string external_id = 6;
}
