//
// Copyright 2019 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 = "proto2";

package gdt_cct;

message LogEvent {
  optional int64 event_time_ms = 1;

  optional int32 event_code = 11;

  optional int64 event_uptime_ms = 17;

  optional bytes source_extension = 6;

  optional sint64 timezone_offset_seconds = 15;

  optional NetworkConnectionInfo network_connection_info = 23;
}

message NetworkConnectionInfo {
  enum NetworkType {
    NONE = -1;
    MOBILE = 0;
    WIFI = 1;
    MOBILE_MMS = 2;
    MOBILE_SUPL = 3;
    MOBILE_DUN = 4;
    MOBILE_HIPRI = 5;
    WIMAX = 6;
    BLUETOOTH = 7;
    DUMMY = 8;
    ETHERNET = 9;
    MOBILE_FOTA = 10;
    MOBILE_IMS = 11;
    MOBILE_CBS = 12;
    WIFI_P2P = 13;
    MOBILE_IA = 14;
    MOBILE_EMERGENCY = 15;
    PROXY = 16;
    VPN = 17;
  }

  enum MobileSubtype {
    UNKNOWN_MOBILE_SUBTYPE = 0;
    GPRS = 1;
    EDGE = 2;
    UMTS = 3;
    CDMA = 4;
    EVDO_0 = 5;
    EVDO_A = 6;
    RTT = 7;
    HSDPA = 8;
    HSUPA = 9;
    HSPA = 10;
    IDEN = 11;
    EVDO_B = 12;
    LTE = 13;
    EHRPD = 14;
    HSPAP = 15;
    GSM = 16;
    TD_SCDMA = 17;
    IWLAN = 18;
    LTE_CA = 19;

    // COMBINED has value -1 in NetworkIdentity, but is given the value
    // 100 here to save (disk) space. The value -1 takes up the full 10 bytes in
    // a varint for enums, but the value 100 only takes up 1 byte.
    COMBINED = 100;
  }

  optional NetworkType network_type = 1 [default = NONE];

  optional MobileSubtype mobile_subtype = 2 [default = UNKNOWN_MOBILE_SUBTYPE];
}

message IosClientInfo {

  // The major OS version of an iOS client. Eg: "8", "9".
  optional string os_major_version = 3;

  // The complete OS version of an iOS client. Eg: "8.4", "9.3".
  optional string os_full_version = 4;

  // The client application build (from Core Foundation key
  // "CFBundleVersion").
  optional string application_build = 5;

  // The chosen country from the client. e.g., "US", "KR", "JP".
  // This is typically populated based on the value of:
  //   [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]
  optional string country = 6;

  // The unix name (uname) for the model from an iOS client. e.g., "iPhone6,1"
  // for iPhone 5s.
  optional string model = 7;

  // The current language displayed to user. e.g., "en", "fr", "en-AU", or "de"
  // This comes from [[NSBundle mainBundle] preferredLocalizations]; and is:
  // "[language designator]" or "[language designator]-[region designator]"
  // format based off of what localization is available and displayed to user.
  optional string language_code = 8;

  // The bundle name of the application.
  optional string application_bundle_id = 11;
}

message ClientInfo {

  enum ClientType {
    CLIENT_UNKNOWN = 0;

    IOS_FIREBASE = 15;
  }

  // The client type for this client. One of the enum values defined above.
  optional ClientType client_type = 1;

  optional IosClientInfo ios_client_info = 4;
}

message BatchedLogRequest {
  repeated LogRequest log_request = 1;
}

message LogRequest {

  optional int64 request_time_ms = 4;

  // Current time since boot in milliseconds, including time spent in sleep,
  // according to the same clock as the one used to set
  // the 'event_uptime_ms' values in the LogEvent protos above.
  optional int64 request_uptime_ms = 8;

  // The ClientInfo at log time.
  optional ClientInfo client_info = 1;

  optional int32 log_source = 2;

  repeated LogEvent log_event = 3;

  optional QosTierConfiguration.QosTier qos_tier = 9 [
    default = DEFAULT];
}

message QosTierConfiguration {

  enum QosTier {
    DEFAULT = 0;

    UNMETERED_ONLY = 1;

    UNMETERED_OR_DAILY = 2;

    FAST_IF_RADIO_AWAKE = 3;

    NEVER = 4;
  }

  optional QosTier qos_tier = 2;

  optional int32 log_source = 3 [default = 0];
}

message QosTiersOverride {
  // Quality of Service tiers enforced by server for overriding client
  // qos_tier setting in event logging.
  // This usually happens when server is burdened with fast qos tiers.
  repeated QosTierConfiguration qos_tier_configuration = 1;

  // The fingerprint of the qos_tier_configuration field.
  optional int64 qos_tier_fingerprint = 2;
}

message LogResponse {
  // Client should wait for next_request_wait_millis before sending the next
  // log request.
  optional int64 next_request_wait_millis = 1;

  // Quality of Service tiers enforced by server for overriding client
  // qos_tier setting in event logging.
  optional QosTiersOverride qos_tier = 3;
}
