// Copyright 2025 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.shopping.merchant.accounts.v1beta;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/field_mask.proto";

option go_package = "cloud.google.com/go/shopping/merchant/accounts/apiv1beta/accountspb;accountspb";
option java_multiple_files = true;
option java_outer_classname = "AutomaticImprovementsProto";
option java_package = "com.google.shopping.merchant.accounts.v1beta";

// Service to manage the automatic improvements of an account. The automatic
// improvements of the account can be used to automatically update products,
// improve images and shipping.
service AutomaticImprovementsService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Retrieves the automatic improvements of an account.
  rpc GetAutomaticImprovements(GetAutomaticImprovementsRequest)
      returns (AutomaticImprovements) {
    option (google.api.http) = {
      get: "/accounts/v1beta/{name=accounts/*/automaticImprovements}"
    };
    option (google.api.method_signature) = "name";
  }

  // Updates the automatic improvements of an account.
  rpc UpdateAutomaticImprovements(UpdateAutomaticImprovementsRequest)
      returns (AutomaticImprovements) {
    option (google.api.http) = {
      patch: "/accounts/v1beta/{automatic_improvements.name=accounts/*/automaticImprovements}"
      body: "automatic_improvements"
    };
    option (google.api.method_signature) = "automatic_improvements,update_mask";
  }
}

// Collection of information related to the [automatic
// improvements](https://developers.google.com/shopping-content/guides/automatic-improvements)
// of an account.
message AutomaticImprovements {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/AutomaticImprovements"
    pattern: "accounts/{account}/automaticImprovements"
    plural: "automaticImprovements"
    singular: "automaticImprovements"
  };

  // Identifier. The resource name of the automatic improvements.
  // Format: `accounts/{account}/automaticImprovements`.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Turning on [item
  // updates](https://support.google.com/merchants/answer/3246284) allows
  // Google to automatically update items for you. When item updates are on,
  // Google uses the structured data markup on the website and advanced data
  // extractors to update the price and availability of the items. When the item
  // updates are off, items with mismatched data aren't shown.
  // This field is only updated (cleared) if provided in the update mask.
  optional AutomaticItemUpdates item_updates = 2;

  // This improvement will attempt to automatically correct submitted images if
  // they don't meet the [image
  // requirements](https://support.google.com/merchants/answer/6324350), for
  // example, removing overlays. If successful, the image will be replaced and
  // approved. This improvement is only applied to images of disapproved offers.
  // For more information see: [Automatic image
  // improvements](https://support.google.com/merchants/answer/9242973)
  // This field is only updated (cleared) if provided in the update mask.
  optional AutomaticImageImprovements image_improvements = 3;

  // Not available for MCAs
  // [accounts](https://support.google.com/merchants/answer/188487). By turning
  // on [automatic shipping
  // improvements](https://support.google.com/merchants/answer/10027038),
  // you are allowing Google to improve the accuracy of your delivery times
  // shown to shoppers using Google. More accurate delivery times, especially
  // when faster, typically lead to better conversion rates. Google will improve
  // your estimated delivery times based on various factors:
  // * Delivery address of an order
  // * Current handling time and shipping time settings
  // * Estimated weekdays or business days
  // * Parcel tracking data
  // This field is only updated (cleared) if provided in the update mask.
  optional AutomaticShippingImprovements shipping_improvements = 4;
}

// Turning on [item
// updates](https://support.google.com/merchants/answer/3246284) allows
// Google to automatically update items for you. When item updates are on,
// Google uses the structured data markup on the website and advanced data
// extractors to update the price and availability of the items. When the item
// updates are off, items with mismatched data aren't shown.
message AutomaticItemUpdates {
  // Settings for the Automatic Item Updates.
  message ItemUpdatesAccountLevelSettings {
    // If price updates are enabled, Google always updates the active price with
    // the crawled information.
    optional bool allow_price_updates = 1;

    // If availability updates are enabled, any previous availability values
    // get overwritten if Google finds an out-of-stock annotation on the offer's
    // page.
    // If additionally `allow_strict_availability_updates` field is set to
    // true, values get overwritten if Google finds an in-stock annotation on
    // the offer’s page.
    optional bool allow_availability_updates = 2;

    // If `allow_availability_updates` is enabled, items are automatically
    // updated in all your Shopping target countries. By default, availability
    // updates will only be applied to items that are 'out of stock' on your
    // website but 'in stock' on Shopping. Set this to true to also update items
    // that are 'in stock' on your website, but 'out of stock' on Google
    // Shopping. In order for this field to have an effect, you must also set
    // `allow_availability_updates`.
    optional bool allow_strict_availability_updates = 3;

    // If condition updates are enabled, Google always updates item condition
    // with the condition detected from the details of your product.
    optional bool allow_condition_updates = 4;
  }

  // Optional. Determines which attributes of the items should be automatically
  // updated. If this field is not present and provided in the update mask, then
  // the settings will be deleted. If there are no settings for subaccount, they
  // are inherited from aggregator.
  ItemUpdatesAccountLevelSettings account_item_updates_settings = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. The effective value of allow_price_updates.
  // If account_item_updates_settings is present, then this value is the same.
  // Otherwise, it represents the inherited value of the parent account.
  // The default value is true if no settings are present.
  // Read-only.
  bool effective_allow_price_updates = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The effective value of allow_availability_updates.
  // If account_item_updates_settings is present, then this value is the same.
  // Otherwise, it represents the inherited value of the parent account.
  // The default value is true if no settings are present.
  // Read-only.
  bool effective_allow_availability_updates = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The effective value of
  // allow_strict_availability_updates.
  // If account_item_updates_settings is present, then this value is the same.
  // Otherwise, it represents the inherited value of the parent account.
  // The default value is true if no settings are present.
  // Read-only.
  bool effective_allow_strict_availability_updates = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The effective value of allow_condition_updates.
  // If account_item_updates_settings is present, then this value is the same.
  // Otherwise, it represents the inherited value of the parent account.
  // The default value is true if no settings are present.
  // Read-only.
  bool effective_allow_condition_updates = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// This improvement will attempt to automatically correct submitted images if
// they don't meet the [image
// requirements](https://support.google.com/merchants/answer/6324350), for
// example, removing overlays. If successful, the image will be replaced and
// approved. This improvement is only applied to images of disapproved offers.
// For more information see: [Automatic image
// improvements](https://support.google.com/merchants/answer/9242973)
message AutomaticImageImprovements {
  // Settings for the Automatic Image Improvements.
  message ImageImprovementsAccountLevelSettings {
    // Enables automatic image improvements.
    optional bool allow_automatic_image_improvements = 1;
  }

  // Optional. Determines how the images should be automatically updated.
  // If this field is not present and provided in the update mask, then the
  // settings will be deleted. If there are no settings for subaccount, they are
  // inherited from aggregator.
  optional ImageImprovementsAccountLevelSettings
      account_image_improvements_settings = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. The effective value of allow_automatic_image_improvements.
  // If account_image_improvements_settings is present, then this value is the
  // same. Otherwise, it represents the inherited value of the parent account.
  // Read-only.
  bool effective_allow_automatic_image_improvements = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Not available for MCAs
// [accounts](https://support.google.com/merchants/answer/188487). By turning on
// [automatic shipping
// improvements](https://support.google.com/merchants/answer/10027038),
// you are allowing Google to improve the accuracy of your delivery times shown
// to shoppers using Google. More accurate delivery times, especially when
// faster, typically lead to better conversion rates. Google will improve your
// estimated delivery times based on various factors:
// * Delivery address of an order
// * Current handling time and shipping time settings
// * Estimated weekdays or business days
// * Parcel tracking data
message AutomaticShippingImprovements {
  // Enables automatic shipping improvements.
  optional bool allow_shipping_improvements = 1;
}

// Request message for the `GetAutomaticImprovements` method.
message GetAutomaticImprovementsRequest {
  // Required. The resource name of the automatic improvements.
  // Format: `accounts/{account}/automaticImprovements`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/AutomaticImprovements"
    }
  ];
}

// Request message for the `UpdateAutomaticImprovements` method.
message UpdateAutomaticImprovementsRequest {
  // Required. The new version of the automatic imrovements.
  AutomaticImprovements automatic_improvements = 1
      [(google.api.field_behavior) = REQUIRED];

  // Required. List of fields being updated.
  // The following fields are supported (in both `snake_case` and
  // `lowerCamelCase`):
  //
  // - `item_updates`
  // - `item_updates.account_level_settings`
  // - `image_improvements`
  // - `image_improvements.account_level_settings`
  // - `shipping_improvements`
  // - `shipping_improvements.allow_shipping_improvements`
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}
