// 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.v2;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/retail/v2/import_config.proto";
import "google/cloud/retail/v2/product.proto";
import "google/cloud/retail/v2/purge_config.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";

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

// Service for ingesting [Product][google.cloud.retail.v2.Product] information
// of the customer's website.
service ProductService {
  option (google.api.default_host) = "retail.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Creates a [Product][google.cloud.retail.v2.Product].
  rpc CreateProduct(CreateProductRequest) returns (Product) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*/locations/*/catalogs/*/branches/*}/products"
      body: "product"
    };
    option (google.api.method_signature) = "parent,product,product_id";
  }

  // Gets a [Product][google.cloud.retail.v2.Product].
  rpc GetProduct(GetProductRequest) returns (Product) {
    option (google.api.http) = {
      get: "/v2/{name=projects/*/locations/*/catalogs/*/branches/*/products/**}"
    };
    option (google.api.method_signature) = "name";
  }

  // Updates a [Product][google.cloud.retail.v2.Product]. Non-existing items
  // will be created.
  rpc UpdateProduct(UpdateProductRequest) returns (Product) {
    option (google.api.http) = {
      patch: "/v2/{product.name=projects/*/locations/*/catalogs/*/branches/*/products/**}"
      body: "product"
    };
    option (google.api.method_signature) = "product,update_mask";
  }

  // Deletes a [Product][google.cloud.retail.v2.Product].
  rpc DeleteProduct(DeleteProductRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v2/{name=projects/*/locations/*/catalogs/*/branches/*/products/**}"
    };
    option (google.api.method_signature) = "name";
  }

  // Bulk import of multiple [Product][google.cloud.retail.v2.Product]s.
  //
  // Request processing may be synchronous. No partial updating is supported.
  // Non-existing items are created.
  //
  // Note that it is possible for a subset of the
  // [Product][google.cloud.retail.v2.Product]s to be successfully updated.
  rpc ImportProducts(ImportProductsRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v2/{parent=projects/*/locations/*/catalogs/*/branches/*}/products:import"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.retail.v2.ImportProductsResponse"
      metadata_type: "google.cloud.retail.v2.ImportMetadata"
    };
  }
}

// Request message for [CreateProduct][] method.
message CreateProductRequest {
  // Required. The parent catalog resource name, such as
  //
  // "projects/*/locations/global/catalogs/default_catalog/branches/default_branch".
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "retail.googleapis.com/Branch" }
  ];

  // Required. The [Product][google.cloud.retail.v2.Product] to create.
  Product product = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The ID to use for the [Product][google.cloud.retail.v2.Product],
  // which will become the final component of the
  // [Product.name][google.cloud.retail.v2.Product.name].
  //
  // If the caller does not have permission to create the
  // [Product][google.cloud.retail.v2.Product], regardless of whether or not it
  // exists, a PERMISSION_DENIED error is returned.
  //
  // This field must be unique among all
  // [Product][google.cloud.retail.v2.Product]s with the same
  // [parent][google.cloud.retail.v2.CreateProductRequest.parent]. Otherwise, an
  // ALREADY_EXISTS error is returned.
  //
  // This field must be a UTF-8 encoded string with a length limit of 128
  // characters. Otherwise, an INVALID_ARGUMENT error is returned.
  string product_id = 3 [(google.api.field_behavior) = REQUIRED];
}

// Request message for [GetProduct][] method.
message GetProductRequest {
  // Required. Full resource name of [Product][google.cloud.retail.v2.Product],
  // such as
  //
  // "projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id".
  //
  // If the caller does not have permission to access the
  // [Product][google.cloud.retail.v2.Product], regardless of whether or not it
  // exists, a PERMISSION_DENIED error is returned.
  //
  // If the requested [Product][google.cloud.retail.v2.Product] does not exist,
  // a NOT_FOUND error is returned.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "retail.googleapis.com/Product" }
  ];
}

// Request message for [UpdateProduct][] method.
message UpdateProductRequest {
  // Required. The product to update/create.
  //
  // If the caller does not have permission to update the
  // [Product][google.cloud.retail.v2.Product], regardless of whether or not it
  // exists, a PERMISSION_DENIED error is returned.
  //
  // If the [Product][google.cloud.retail.v2.Product] to update does not exist,
  // a NOT_FOUND error is returned.
  Product product = 1 [(google.api.field_behavior) = REQUIRED];

  // Indicates which fields in the provided
  // [Product][google.cloud.retail.v2.Product] to update. The immutable and
  // output only fields are NOT supported. If not set, all supported fields (the
  // fields that are neither immutable nor output only) are updated.
  //
  // If an unsupported or unknown field is provided, an INVALID_ARGUMENT error
  // is returned.
  google.protobuf.FieldMask update_mask = 2;
}

// Request message for [DeleteProduct][] method.
message DeleteProductRequest {
  // Required. Full resource name of [Product][google.cloud.retail.v2.Product],
  // such as
  //
  // "projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id".
  //
  // If the caller does not have permission to delete the
  // [Product][google.cloud.retail.v2.Product], regardless of whether or not it
  // exists, a PERMISSION_DENIED error is returned.
  //
  // If the [Product][google.cloud.retail.v2.Product] to delete does not exist,
  // a NOT_FOUND error is returned.
  //
  // The [Product][google.cloud.retail.v2.Product] to delete can neither be a
  // non-empty [Product.Type.COLLECTION][]
  // [Product][google.cloud.retail.v2.Product] nor a [Product.Type.PRIMARY][]
  // [Product][google.cloud.retail.v2.Product] with more than one
  // [variants][Product.Type.VARIANT]. Otherwise, a FAILED_PRECONDITION error is
  // returned.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "retail.googleapis.com/Product" }
  ];
}
