// Copyright 2018 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.cloud.vision.v1;

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

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


// Parameters for a product search request.
message ProductSearchParams {
  // 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;

  // The resource name of a [ProductSet][google.cloud.vision.v1.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", "apparel", or "toys" 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 Result {
    // The Product.
    Product product = 1;

    // A confidence level on the match, ranging from 0 (no confidence) to
    // 1 (full confidence).
    float score = 2;

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

  // Information about the products similar to a single product in a query
  // image.
  message GroupedResult {
    // The bounding polygon around the product detected in the query image.
    BoundingPoly bounding_poly = 1;

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

  // 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 results, one for each product match.
  repeated Result results = 5;

  // List of results grouped by products detected in the query image. Each entry
  // corresponds to one bounding polygon in the query image, and contains the
  // matching products specific to that region. There may be duplicate product
  // matches in the union of all the per-product results.
  repeated GroupedResult product_grouped_results = 6;
}
