// 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.ads.googleads.v5.common;

import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";

option csharp_namespace = "Google.Ads.GoogleAds.V5.Common";
option go_package = "google.golang.org/genproto/googleapis/ads/googleads/v5/common;common";
option java_multiple_files = true;
option java_outer_classname = "OfflineUserDataProto";
option java_package = "com.google.ads.googleads.v5.common";
option objc_class_prefix = "GAA";
option php_namespace = "Google\\Ads\\GoogleAds\\V5\\Common";
option ruby_package = "Google::Ads::GoogleAds::V5::Common";

// Proto file describing offline user data.

// Address identifier of offline data.
message OfflineUserAddressInfo {
  // First name of the user, which is hashed as SHA-256 after normalized
  // (Lowercase all characters; Remove any extra spaces before, after, and in
  // between).
  google.protobuf.StringValue hashed_first_name = 1;

  // Last name of the user, which is hashed as SHA-256 after normalized (lower
  // case only and no punctuation).
  google.protobuf.StringValue hashed_last_name = 2;

  // City of the address. Only accepted for Store Sales Direct data.
  google.protobuf.StringValue city = 3;

  // State code of the address. Only accepted for Store Sales Direct data.
  google.protobuf.StringValue state = 4;

  // 2-letter country code in ISO-3166-1 alpha-2 of the user's address.
  google.protobuf.StringValue country_code = 5;

  // Postal code of the user's address.
  google.protobuf.StringValue postal_code = 6;
}

// Hashed user identifying information.
message UserIdentifier {
  // Exactly one must be specified.
  oneof identifier {
    // Hashed email address using SHA-256 hash function after normalization.
    google.protobuf.StringValue hashed_email = 1;

    // Hashed phone number using SHA-256 hash function after normalization
    // (E164 standard).
    google.protobuf.StringValue hashed_phone_number = 2;

    // Mobile device ID (advertising ID/IDFA).
    google.protobuf.StringValue mobile_id = 3;

    // Advertiser-assigned user ID for Customer Match upload, or
    // third-party-assigned user ID for SSD.
    google.protobuf.StringValue third_party_user_id = 4;

    // Address information.
    OfflineUserAddressInfo address_info = 5;
  }
}

// Attribute of the store sales transaction.
message TransactionAttribute {
  // Timestamp when transaction occurred. Required.
  // The format is "YYYY-MM-DD HH:MM:SS".
  // Examples: "2018-03-05 09:15:00" or "2018-02-01 14:34:30"
  google.protobuf.StringValue transaction_date_time = 1;

  // Transaction amount in micros. Required.
  google.protobuf.DoubleValue transaction_amount_micros = 2;

  // Transaction currency code. ISO 4217 three-letter code is used. Required.
  google.protobuf.StringValue currency_code = 3;

  // The resource name of conversion action to report conversions to.
  // Required.
  google.protobuf.StringValue conversion_action = 4;

  // Transaction order id.
  // Accessible only to customers on the allow-list.
  google.protobuf.StringValue order_id = 5;

  // Store attributes of the transaction.
  // Accessible only to customers on the allow-list.
  StoreAttribute store_attribute = 6;

  // Value of the custom variable for each transaction.
  // Accessible only to customers on the allow-list.
  google.protobuf.StringValue custom_value = 7;
}

// Store attributes of the transaction.
message StoreAttribute {
  // Store code from
  // https://support.google.com/business/answer/3370250#storecode
  google.protobuf.StringValue store_code = 1;
}

// User data holding user identifiers and attributes.
message UserData {
  // User identification info. Required.
  repeated UserIdentifier user_identifiers = 1;

  // Additional transactions/attributes associated with the user.
  // Required when updating store sales data.
  TransactionAttribute transaction_attribute = 2;
}

// Metadata for customer match user list.
message CustomerMatchUserListMetadata {
  // The resource name of remarketing list to update data.
  // Required for job of CUSTOMER_MATCH_USER_LIST type.
  google.protobuf.StringValue user_list = 1;
}

// Metadata for Store Sales Direct.
message StoreSalesMetadata {
  // This is the fraction of all transactions that are identifiable (i.e.,
  // associated with any form of customer information).
  // Required.
  // The fraction needs to be between 0 and 1 (excluding 0).
  google.protobuf.DoubleValue loyalty_fraction = 1;

  // This is the ratio of sales being uploaded compared to the overall sales
  // that can be associated with a customer. Required.
  // The fraction needs to be between 0 and 1 (excluding 0). For example, if you
  // upload half the sales that you are able to associate with a customer, this
  // would be 0.5.
  google.protobuf.DoubleValue transaction_upload_fraction = 2;

  // Name of the store sales custom variable key. A predefined key that
  // can be applied to the transaction and then later used for custom
  // segmentation in reporting.
  // Accessible only to customers on the allow-list.
  google.protobuf.StringValue custom_key = 4;

  // Metadata for a third party Store Sales upload.
  StoreSalesThirdPartyMetadata third_party_metadata = 3;
}

// Metadata for a third party Store Sales.
// This product is only for customers on the allow-list. Please contact your
// Google business development representative for details on the upload
// configuration.
message StoreSalesThirdPartyMetadata {
  // Time the advertiser uploaded the data to the partner. Required.
  // The format is "YYYY-MM-DD HH:MM:SS".
  // Examples: "2018-03-05 09:15:00" or "2018-02-01 14:34:30"
  google.protobuf.StringValue advertiser_upload_date_time = 1;

  // The fraction of transactions that are valid. Invalid transactions may
  // include invalid formats or values.
  // Required.
  // The fraction needs to be between 0 and 1 (excluding 0).
  google.protobuf.DoubleValue valid_transaction_fraction = 2;

  // The fraction of valid transactions that are matched to a third party
  // assigned user ID on the partner side.
  // Required.
  // The fraction needs to be between 0 and 1 (excluding 0).
  google.protobuf.DoubleValue partner_match_fraction = 3;

  // The fraction of valid transactions that are uploaded by the partner to
  // Google.
  // Required.
  // The fraction needs to be between 0 and 1 (excluding 0).
  google.protobuf.DoubleValue partner_upload_fraction = 4;

  // Version of partner IDs to be used for uploads. Required.
  google.protobuf.StringValue bridge_map_version_id = 5;

  // ID of the third party partner updating the transaction feed.
  google.protobuf.Int64Value partner_id = 6;
}
