// 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.cloud.retail.v2beta;

import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.Retail.V2Beta";
option go_package = "google.golang.org/genproto/googleapis/cloud/retail/v2beta;retail";
option java_multiple_files = true;
option java_outer_classname = "ExportConfigProto";
option java_package = "com.google.cloud.retail.v2beta";
option objc_class_prefix = "RETAIL";
option php_namespace = "Google\\Cloud\\Retail\\V2beta";
option ruby_package = "Google::Cloud::Retail::V2beta";

// The output configuration setting.
message OutputConfig {
  // The Google Cloud Storage output destination configuration.
  message GcsDestination {
    // Required. The output uri prefix for saving output data to json files.
    // Some mapping examples are as follows:
    // output_uri_prefix         sample output(assuming the object is foo.json)
    // ========================  =============================================
    // gs://bucket/              gs://bucket/foo.json
    // gs://bucket/folder/       gs://bucket/folder/foo.json
    // gs://bucket/folder/item_  gs://bucket/folder/item_foo.json
    string output_uri_prefix = 1 [(google.api.field_behavior) = REQUIRED];
  }

  // The BigQuery output destination configuration.
  message BigQueryDestination {
    // The ID of a BigQuery Dataset.
    string dataset_id = 1;
  }

  // The configuration of destination for holding output data.
  oneof destination {
    // The Google Cloud Storage location where the output is to be written to.
    GcsDestination gcs_destination = 1;

    // The BigQuery location where the output is to be written to.
    BigQueryDestination bigquery_destination = 2;
  }
}

// Configuration of destination for Export related errors.
message ExportErrorsConfig {
  // Required. Errors destination.
  oneof destination {
    // Google Cloud Storage path for import errors. This must be an empty,
    // existing Cloud Storage bucket. Export errors will be written to a file in
    // this bucket, one per line, as a JSON-encoded
    // `google.rpc.Status` message.
    string gcs_prefix = 1;
  }
}

// Request message for ExportProducts method.
message ExportProductsRequest {
  // Required.
  // "projects/1234/locations/global/catalogs/default_catalog/branches/default_branch"
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The desired output location of the data.
  OutputConfig output_config = 2 [(google.api.field_behavior) = REQUIRED];

  // Filtering expression to specify restrictions over
  // returned products. This is a sequence of terms, where each term applies
  // some kind of a restriction to the returned products. Use this expression to
  // restrict results to a specific time range, tag, stock state or filter
  // products by product type.
  //    eg: lastModifiedTime > "2012-04-23T18:25:43.511Z"
  //    lastModifiedTime<"2012-04-23T18:25:43.511Z" productType=primary
  //
  //   We expect only 4 types of fields:
  //
  //    * lastModifiedTime: this can be specified a maximum of 2 times, once
  //    with a
  //      less than operator and once with a greater than operator. The
  //      lastModifiedTime restrict should result in one contiguous valid last
  //      modified time range.
  //
  //    * productType: supported values are 'primary' and 'variant'. Boolean
  //    operators `OR` and `NOT` are supported if the
  //      expression is enclosed in parentheses, and must be separated from the
  //      productType values by a space.
  //
  //    * availability: supported values are IN_STOCK, OUT_OF_STOCK,
  //    PREORDER and BACKORDER. Boolean operators `OR` and `NOT` are
  //    supported if the
  //      expression is enclosed in parentheses, and must be separated from the
  //      availability values by a space.
  //
  //    * Tag expressions. Restricts output to products that match all of the
  //      specified tags. Boolean operators `OR` and `NOT` are supported if the
  //      expression is enclosed in parentheses, and must be separated from the
  //      tag values by a space. `-"tagA"` is also supported and is equivalent
  //      to `NOT "tagA"`. Tag values must be double quoted UTF-8 encoded
  //      strings with a size limit of 1,000 characters.
  //
  //   Some examples of valid filters expressions:
  //
  //   * Example 1: lastModifiedTime > "2012-04-23T18:25:43.511Z"
  //             lastModifiedTime < "2012-04-23T18:30:43.511Z"
  //   * Example 2: lastModifiedTime > "2012-04-23T18:25:43.511Z"
  //             productType = "variant"
  //   * Example 3: tag=("Red" OR "Blue") tag="New-Arrival"
  //             tag=(NOT "promotional")
  //             productType = "primary" lastModifiedTime <
  //             "2018-04-23T18:30:43.511Z"
  //   * Example 4: lastModifiedTime > "2012-04-23T18:25:43.511Z"
  //   * Example 5: availability = (IN_STOCK OR BACKORDER)
  string filter = 3;
}

// Request message for ExportUserEvents method.
message ExportUserEventsRequest {
  // Required. "projects/1234/locations/global/catalogs/default_catalog"
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The desired output location of the data.
  OutputConfig output_config = 2 [(google.api.field_behavior) = REQUIRED];

  // Filtering expression to specify restrictions over
  // returned events. This is a sequence of terms, where each term applies some
  // kind of a restriction to the returned user events. Use this expression to
  // restrict results to a specific time range, or filter events by eventType.
  //    eg: eventTime > "2012-04-23T18:25:43.511Z" eventsMissingCatalogItems
  //    eventTime<"2012-04-23T18:25:43.511Z" eventType=search
  //
  //   We expect only 3 types of fields:
  //
  //    * eventTime: this can be specified a maximum of 2 times, once with a
  //      less than operator and once with a greater than operator. The
  //      eventTime restrict should result in one contiguous valid eventTime
  //      range.
  //
  //    * eventType: Boolean operators `OR` and `NOT` are supported if the
  //      expression is enclosed in parentheses, and must be separated from the
  //      tag values by a space.
  //
  //    * eventsMissingCatalogItems: specifying this will restrict results
  //      to events for which catalog items were not found in the catalog. The
  //      default behavior is to return only those events for which catalog
  //      items were found.
  //
  //   Some examples of valid filters expressions:
  //
  //   * Example 1: eventTime > "2012-04-23T18:25:43.511Z"
  //             eventTime < "2012-04-23T18:30:43.511Z"
  //   * Example 2: eventTime > "2012-04-23T18:25:43.511Z"
  //             eventType = detail-page-view
  //   * Example 3: eventsMissingCatalogItems
  //             eventType = (NOT search) eventTime < "2018-04-23T18:30:43.511Z"
  //   * Example 4: eventTime > "2012-04-23T18:25:43.511Z"
  //   * Example 5: eventType = (search OR impression)
  //   * Example 6: eventsMissingCatalogItems
  string filter = 3;
}

// Metadata related to the progress of the Export operation. This will be
// returned by the google.longrunning.Operation.metadata field.
message ExportMetadata {
  // Operation create time.
  google.protobuf.Timestamp create_time = 1;

  // Operation last update time. If the operation is done, this is also the
  // finish time.
  google.protobuf.Timestamp update_time = 2;
}

// Response of the ExportProductsRequest. If the long running
// operation is done, then this message is returned by the
// google.longrunning.Operations.response field if the operation was successful.
message ExportProductsResponse {
  // A sample of errors encountered while processing the request.
  repeated google.rpc.Status error_samples = 1;

  // Echoes the destination for the complete errors in the request if set.
  ExportErrorsConfig errors_config = 2;
}

// Response of the ExportUserEventsRequest. If the long running
// operation was successful, then this message is returned by the
// google.longrunning.Operations.response field if the operation was successful.
message ExportUserEventsResponse {
  // A sample of errors encountered while processing the request.
  repeated google.rpc.Status error_samples = 1;

  // Echoes the destination for the complete errors if this field was set in
  // the request.
  ExportErrorsConfig errors_config = 2;
}
