// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

package commerce;

option java_package = "org.chromium.components.commerce";

option optimize_for = LITE_RUNTIME;

import "components/commerce/core/proto/product_category.proto";

// These messages are primarily used for over-the-wire communications. If this
// information needs to be stored locally, consider building a separate proto.
message PriceTrackingData {
  // metadata relating to the product
  optional BuyableProduct buyable_product = 1;

  // price update data for the product
  optional ProductPriceUpdate product_update = 2;
}

message BuyableProduct {
  enum ProductReferenceType {
    UNKNOWN = 0;
    // The product referenced in the product details page.
    MAIN_PRODUCT = 1;
  }

  // Recommendation on how to display the price range to the consumer.
  enum PriceDisplayRecommendation {
    // No recommendation.
    RECOMMENDATION_UNSPECIFIED = 0;
    // Show the price range as is.
    RECOMMENDATION_SHOW_RANGE = 1;
    // Show the lower bound of the price range.
    RECOMMENDATION_SHOW_RANGE_LOWER_BOUND = 2;
    // Show the upper bound of the price range.
    RECOMMENDATION_SHOW_RANGE_UPPER_BOUND = 3;
    // Show a '-'.
    RECOMMENDATION_SHOW_PRICE_UNDETERMINED = 4;
    // Show the single price.
    RECOMMENDATION_SHOW_SINGLE_PRICE = 5;
  }

  // One offer title of the product in the current page.
  optional string title = 1;

  // Direct link to the product image.
  optional string image_url = 2;

  // Price as shown in the page.
  optional ProductPrice current_price = 3;

  // Determines how the product is referenced in the current page.
  optional ProductReferenceType reference_type = 4;

  // Docid of the offer.
  optional fixed64 offer_id = 5;

  // Cluster id.
  optional uint64 product_cluster_id = 6;

  // Country code of the offer.
  optional string country_code = 7;

  // The title of the product cluster. This differs from above offer title in
  // that it would exclude attributes (size, color, etc.) and instead describes
  // a broader range of the same product.
  optional string gpc_title = 8;

  // Category data of this product.
  optional CategoryData category_data = 9;

  // Lowest and highest price offers.
  repeated PriceSummary price_summary = 10;

  // The price display recommendation.
  optional PriceDisplayRecommendation price_display_recommendation = 11;

  // Aggregate reviews for the product.
  optional ProductReviews product_reviews = 12;
}

message PriceSummary {
  // The condition of the offers considered in the price summary.
  enum ProductOfferCondition {
    CONDITION_UNKNOWN = 0;
    // The offers are any condition.
    CONDITION_ANY = 1;
    // The offers are all new products.
    CONDITION_NEW = 2;
  }

  // The condition of the offers in this summary.
  optional ProductOfferCondition condition = 1;

  // The lowest price offer.
  optional ProductPrice lowest_price = 2;

  // The highest price offer.
  optional ProductPrice highest_price = 3;

  // Whether this is the preferred price summary in this list.
  optional bool is_preferred = 4;
}

message ProductPriceUpdate {
  // Docid of the offer represented by this update.
  optional fixed64 offer_id = 1;

  // Old price as seen on the shopping backend.
  optional ProductPrice old_price = 2;

  // New price as seen on the shopping backend.
  optional ProductPrice new_price = 3;
}

message ProductPrice {
  // Code for the currency e.g. USD.
  optional string currency_code = 1;

  // Price in micros.
  optional int64 amount_micros = 2;
}

message ProductReviews {
  // The number of reviews for the product.
  optional int32 review_count = 1;

  // The average rating of the product.
  optional float average_rating = 2;
}

// TODO(crbug.com/40251440) Remove PriceDropNotificationPayload
// from chrome/browser/commerce/price_tracking/proto/notifications.proto
// and migrate usages of PriceDropNotificationPayload from chrome/browser
// to here in components.
message PriceDropNotificationPayload {
  optional string product_name = 1;
  optional uint64 offer_id = 2;
  optional string destination_url = 3;
  optional ProductPrice current_price = 4;
  optional ProductPrice previous_price = 5;
  optional uint64 product_cluster_id = 6;
}
