// Copyright 2021 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";

package google.internal.communications.instantmessaging.v1;

import "frameworks/testing/rpcreplay/processors/rpc_replay_field_option.proto";
import "internal/proto/tachyon_enums.proto";

option optimize_for = LITE_RUNTIME;

message Id {
  // type defines what the id field contains, e.g. phone number, Fi-number, Gaia
  // ID etc.
  IdType.Type type = 1;
  // id is a unique (for this type and app) identifier of a message source or
  // recipient.
  string id = 2;

  // app is the tachyon client application that generated or is to receive a
  // message.
  string app = 3;

  // location_hint is used as a hint for the user's region.
  LocationHint location_hint = 5;
}

// LocationHint is used to specify a location as well as format.
message LocationHint {
  // Location is the location, provided in the format specified by format.
  string location = 1;

  // the format of location.
  LocationStandard.Format format = 2;
}

// RequestHeader must be included in all request messages with the field name
// `header`.
// This will make the generated Go types of requests have GetHeader and
// SetHeader funcs, which makes it simple to create a common interface to access
// the header values.
message RequestHeader {
  // request_id identifies this request and its responses, must be unique, and
  // is generated by the request creator.
  // This does not need to be set if request_id_binary is set.
  string request_id = 1;

  // app identifies the application; this is used to isolate different
  // applications in the backend.
  string app = 3;

  // client_info holds information about the calling client application.
  ClientInfo client_info = 7;

  // requester_id is the user ID of the requester.
  Id requester_id = 10;
}

// ResponseHeader must be included in all response messages with the field name
// `header`.
// This will make the generated Go types of responses have GetHeader and
// SetHeader funcs, which makes it simple to create a common interface to access
// the header values.
message ResponseHeader {
  reserved 3, 102;

  // rpc_global_id holds the global dapper trace id of the request that produced
  // this response.
  uint64 rpc_global_id = 2 [
    jstype = JS_STRING,
    (rpcreplay.processing).rewrite_identifier = "TACHYON_RPC_GLOBAL_ID"
  ];

  // txn_timestamp_usec indicates the timestamp that the response data was read
  // at.
  int64 txn_timestamp_usec = 4
      [(rpcreplay.processing).rewrite_time = MICROSECONDS];

  // api_version_warning is set by the server when the ClientInfo in the request
  // indicate that the client was built against a API version that is soon to be
  // deprecated. Clients should show a UI to the user asking them to update the
  // application.
  // @deprecated
  ApiVersionWarning api_version_warning = 103;
}

message ApiVersionWarning {
  // grumble_at is API version where the server starts to complain.
  ApiVersion.Value grumble_at = 1;

  // fail_at is the API version where the server no longer accepts requests.
  ApiVersion.Value fail_at = 2;
}

message ClientInfo {
  // major, minor, point and details carry version information from client.
  int32 major = 3;
  int32 minor = 4;
  int32 point = 5;

  // api_version identifies what api_version the client was built against.
  // This is used by server to:
  // - push warning messages to clients during bind
  // - fail RPCs if client is using a too old version
  // - add backwards compatible code
  ApiVersion.Value api_version = 7;

  // platform_type is the type of platform, used to construct user agent string
  // and to determine client node type in logging.
  Platform.Type platform_type = 9;

  // The APK version name (e.g. "4.0.006_RC2").
  // Fireball Android sends down the version code in the above major field and
  // leaves minor and point empty. The code results in a version that is tough
  // to decipher like "20011296.0.0". The version name here is formatted to make
  // versioning easier and safer on the server. Currently, this field is only
  // populated by Fireball Android. See go/fireball-gbot-version.
  string app_version = 10;
}

message InboxMessage {
  string message_id = 1;

  enum MessageType {
    UNKNOWN = 0;
    BASIC = 4;
  }
  MessageType message_type = 2;

  bytes message = 12;

  enum MessageClass {
    USER = 0;
    EPHEMERAL = 2;
  }
  MessageClass message_class = 5;
}

// Matches StreamBody definition from the server:
// google3/google/rpc/stream_body.proto
message StreamBody {
  repeated bytes messages = 1;
  repeated bytes noop = 15;
}

// Echo request and response for clients to test the network connectivity.
// (== suppress_warning documentation-presence ==)
message EchoRequest {
  RequestHeader header = 1;
  bytes payload = 2;
}

// (== suppress_warning documentation-presence ==)
message EchoResponse {
  ResponseHeader header = 1;
  bytes payload = 2;
}
