// Copyright 2018 Google Inc.
//
// 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.vision.v1p3beta1;

import "google/api/annotations.proto";
import "google/cloud/vision/v1p3beta1/geometry.proto";
import "google/cloud/vision/v1p3beta1/product_search_service.proto";
import "google/protobuf/timestamp.proto";

option cc_enable_arenas = true;
option go_package = "google.golang.org/genproto/googleapis/cloud/vision/v1p3beta1;vision";
option java_multiple_files = true;
option java_outer_classname = "ProductSearchProto";
option java_package = "com.google.cloud.vision.v1p3beta1";

// Parameters for a product search request.
message ProductSearchParams {
  // The resource name of the catalog to search.
  //
  // Format is: `productSearch/catalogs/CATALOG_NAME`.
  string catalog_name = 1;

  // The category to search in.
  // Optional. It is inferred by the system if it is not specified.
  // [Deprecated] Use `product_category`.
  ProductSearchCategory category = 2;

  // The product category to search in.
  // Optional. It is inferred by the system if it is not specified.
  // Supported values are `bag`, `shoe`, `sunglasses`, `dress`, `outerwear`,
  // `skirt`, `top`, `shorts`, and `pants`.
  string product_category = 5;

  // The bounding polygon around the area of interest in the image.
  // Optional. If it is not specified, system discretion will be applied.
  // [Deprecated] Use `bounding_poly`.
  NormalizedBoundingPoly normalized_bounding_poly = 3;

  // The bounding polygon around the area of interest in the image.
  // Optional. If it is not specified, system discretion will be applied.
  BoundingPoly bounding_poly = 9;

  // Specifies the verbosity of the  product search results.
  // Optional. Defaults to `BASIC`.
  ProductSearchResultsView view = 4;

  // The resource name of a
  // [ProductSet][google.cloud.vision.v1p3beta1.ProductSet] to be searched for
  // similar images.
  //
  // Format is:
  // `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`.
  string product_set = 6;

  // The list of product categories to search in. Currently, we only consider
  // the first category, and either "homegoods" or "apparel" should be
  // specified.
  repeated string product_categories = 7;

  // The filtering expression. This can be used to restrict search results based
  // on Product labels. We currently support an AND of OR of key-value
  // expressions, where each expression within an OR must have the same key.
  //
  // For example, "(color = red OR color = blue) AND brand = Google" is
  // acceptable, but not "(color = red OR brand = Google)" or "color: red".
  string filter = 8;
}

// Results for a product search request.
message ProductSearchResults {
  // Information about a product.
  message ProductInfo {
    // Product ID.
    string product_id = 1;

    // The URI of the image which matched the query image.
    //
    // This field is returned only if `view` is set to `FULL` in
    // the request.
    string image_uri = 2;

    // A confidence level on the match, ranging from 0 (no confidence) to
    // 1 (full confidence).
    //
    // This field is returned only if `view` is set to `FULL` in
    // the request.
    float score = 3;
  }

  // Information about a product.
  message Result {
    // The Product.
    Product product = 1;

    // A confidence level on the match, ranging from 0 (no confidence) to
    // 1 (full confidence).
    //
    // This field is returned only if `view` is set to `FULL` in
    // the request.
    float score = 2;

    // The resource name of the image from the product that is the closest match
    // to the query.
    string image = 3;
  }

  // Product category.
  // [Deprecated] Use `product_category`.
  ProductSearchCategory category = 1;

  // Product category.
  // Supported values are `bag` and `shoe`.
  // [Deprecated] `product_category` is provided in each Product.
  string product_category = 4;

  // Timestamp of the index which provided these results. Changes made after
  // this time are not reflected in the current results.
  google.protobuf.Timestamp index_time = 2;

  // List of detected products.
  repeated ProductInfo products = 3;

  // List of results, one for each product match.
  repeated Result results = 5;
}

// Supported product search categories.
enum ProductSearchCategory {
  // Default value used when a category is not specified.
  PRODUCT_SEARCH_CATEGORY_UNSPECIFIED = 0;

  // Shoes category.
  SHOES = 1;

  // Bags category.
  BAGS = 2;
}

// Specifies the fields to include in product search results.
enum ProductSearchResultsView {
  // Product search results contain only `product_category` and `product_id`.
  // Default value.
  BASIC = 0;

  // Product search results contain `product_category`, `product_id`,
  // `image_uri`, and `score`.
  FULL = 1;
}
