// Copyright 2026 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.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/wrappers.proto";
import "google/type/latlng.proto";

option csharp_namespace = "Google.Shopping.Merchant.Accounts.V1";
option go_package = "cloud.google.com/go/shopping/merchant/accounts/apiv1/accountspb;accountspb";
option java_multiple_files = true;
option java_outer_classname = "RegionsProto";
option java_package = "com.google.shopping.merchant.accounts.v1";
option php_namespace = "Google\\Shopping\\Merchant\\Accounts\\V1";
option ruby_package = "Google::Shopping::Merchant::Accounts::V1";

// Manages regions configuration.
//
// This API defines the following resource model:
//
// - [Region][google.shopping.merchant.accounts.v1.Region]
service RegionsService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Retrieves a region defined in your Merchant Center account.
  rpc GetRegion(GetRegionRequest) returns (Region) {
    option (google.api.http) = {
      get: "/accounts/v1/{name=accounts/*/regions/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a region definition in your Merchant Center account. Executing this
  // method requires admin access.
  rpc CreateRegion(CreateRegionRequest) returns (Region) {
    option (google.api.http) = {
      post: "/accounts/v1/{parent=accounts/*}/regions"
      body: "region"
    };
    option (google.api.method_signature) = "parent,region,region_id";
  }

  // Creates one or more regions in your Merchant Center account.
  // Executing this method requires admin access.
  rpc BatchCreateRegions(BatchCreateRegionsRequest)
      returns (BatchCreateRegionsResponse) {
    option (google.api.http) = {
      post: "/accounts/v1/{parent=accounts/*}/regions:batchCreate"
      body: "*"
    };
  }

  // Updates a region definition in your Merchant Center account.
  // Executing this method requires admin access.
  rpc UpdateRegion(UpdateRegionRequest) returns (Region) {
    option (google.api.http) = {
      patch: "/accounts/v1/{region.name=accounts/*/regions/*}"
      body: "region"
    };
    option (google.api.method_signature) = "region,update_mask";
  }

  // Updates one or more regions in your Merchant Center account.
  // Executing this method requires admin access.
  rpc BatchUpdateRegions(BatchUpdateRegionsRequest)
      returns (BatchUpdateRegionsResponse) {
    option (google.api.http) = {
      post: "/accounts/v1/{parent=accounts/*}/regions:batchUpdate"
      body: "*"
    };
  }

  // Deletes a region definition from your Merchant Center account. Executing
  // this method requires admin access.
  rpc DeleteRegion(DeleteRegionRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/accounts/v1/{name=accounts/*/regions/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Deletes multiple regions by name from your Merchant Center account.
  // Executing this method requires admin access.
  rpc BatchDeleteRegions(BatchDeleteRegionsRequest)
      returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/accounts/v1/{parent=accounts/*}/regions:batchDelete"
      body: "*"
    };
  }

  // Lists the regions in your Merchant Center account.
  rpc ListRegions(ListRegionsRequest) returns (ListRegionsResponse) {
    option (google.api.http) = {
      get: "/accounts/v1/{parent=accounts/*}/regions"
    };
    option (google.api.method_signature) = "parent";
  }
}

// Request message for the `GetRegion` method.
message GetRegionRequest {
  // Required. The name of the region to retrieve.
  // Format: `accounts/{account}/regions/{region}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Region"
    }
  ];
}

// Request message for the `CreateRegion` method.
message CreateRegionRequest {
  // Required. The account to create a region for.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Required. The identifier for the region, unique over all regions of the
  // same account.
  string region_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The region to create.
  Region region = 3 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `BatchCreateRegions` method.
message BatchCreateRegionsRequest {
  // Required. The account to create one or more regions for.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Required. The region(s) to create.
  // The maximum number of regions that can be created in a batch is 100.
  repeated CreateRegionRequest requests = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Response message for the `BatchCreateRegions` method.
message BatchCreateRegionsResponse {
  // The created region(s).
  repeated Region regions = 1;
}

// Request message for the `UpdateRegion` method.
message UpdateRegionRequest {
  // Required. The updated region.
  Region region = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The comma-separated field mask indicating the fields to update.
  // Example:
  // `"displayName,postalCodeArea.regionCode"`.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// Request message for the `BatchUpdateRegions` method.
message BatchUpdateRegionsRequest {
  // Required. The account to update one or more regions for.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Required. The region(s) to update.
  // The maximum number of regions that can be updated in a batch is 100.
  repeated UpdateRegionRequest requests = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Response message for the `BatchUpdateRegions` method.
message BatchUpdateRegionsResponse {
  // The updated region(s).
  repeated Region regions = 1;
}

// Request message for the `DeleteRegion` method.
message DeleteRegionRequest {
  // Required. The name of the region to delete.
  // Format: `accounts/{account}/regions/{region}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Region"
    }
  ];
}

// Request message for the `BatchDeleteRegions` method.
message BatchDeleteRegionsRequest {
  // Required. The account to delete one or more regions from.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Required. The names of the regions to delete.
  // A maximum of 100 regions can be deleted in a batch.
  repeated DeleteRegionRequest requests = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `ListRegions` method.
message ListRegionsRequest {
  // Required. The account to list regions for.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Optional. The maximum number of regions to return. The service may return
  // fewer than this value.
  // If unspecified, at most 50 regions will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `ListRegions` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListRegions` must
  // match the call that provided the page token.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for the `ListRegions` method.
message ListRegionsResponse {
  // The regions from the specified business.
  repeated Region regions = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// Represents a geographic region that you can use as a target with both the
// `RegionalInventory` and `ShippingSettings` services. You can define regions
// as collections of either postal codes, radius areas or, in some countries,
// using predefined geotargets.
//
// A region must be defined by specifying exactly one of `postal_code_area`,
// `geotarget_area`, or `radius_area`.
//
// For more information, see [Set up regions
// ](https://support.google.com/merchants/answer/7410946#zippy=%2Ccreate-a-new-region)
// for more information.
message Region {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/Region"
    pattern: "accounts/{account}/regions/{region}"
    plural: "regions"
    singular: "region"
  };

  // A list of postal codes that defines the region area.
  // Note: All regions defined using postal codes are accessible through the
  // account's `ShippingSettings.postalCodeGroups` resource.
  message PostalCodeArea {
    // A range of postal codes that defines the region area.
    message PostalCodeRange {
      // Required. A postal code or a pattern of the form prefix* denoting the
      // inclusive lower bound of the range defining the area. Examples values:
      // `94108`, `9410*`, `9*`.
      string begin = 1 [(google.api.field_behavior) = REQUIRED];

      // Optional. A postal code or a pattern of the form `prefix*` denoting the
      // inclusive upper bound of the range defining the area. It must have the
      // same length as postalCodeRangeBegin: if postalCodeRangeBegin is a
      // postal code then postalCodeRangeEnd must be a postal code too; if
      // postalCodeRangeBegin is a pattern then postalCodeRangeEnd must be a
      // pattern with the same prefix length. Optional: if not set, then the
      // area is defined as being all the postal codes matching
      // postalCodeRangeBegin.
      string end = 2 [(google.api.field_behavior) = OPTIONAL];
    }

    // Required. [CLDR territory
    // code](http://www.unicode.org/repos/cldr/tags/latest/common/main/en.xml)
    // or the country the postal code group applies to.
    string region_code = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. A range of postal codes.
    repeated PostalCodeRange postal_codes = 2
        [(google.api.field_behavior) = REQUIRED];
  }

  // A list of geotargets that defines the region area.
  message GeoTargetArea {
    // Required. A non-empty list of [location
    // IDs](https://developers.google.com/adwords/api/docs/appendix/geotargeting).
    // They must all be of the same location type (for example, state).
    repeated int64 geotarget_criteria_ids = 1
        [(google.api.field_behavior) = REQUIRED];
  }

  // A radius area that defines the region area.
  message RadiusArea {
    // The unit of measurement of the radius. Default is KILOMETERS.
    enum RadiusUnits {
      // Unused default value
      RADIUS_UNITS_UNSPECIFIED = 0;

      // The distance is measured in miles.
      MILES = 1;

      // The distance is measured in kilometers.
      KILOMETERS = 2;
    }

    // Required. [CLDR territory
    // code](http://www.unicode.org/repos/cldr/tags/latest/common/main/en.xml)
    // or the country the radius area applies to.
    string region_code = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. The center of the radius area. It represents a
    // latitude/longitude pair in decimal degrees format.
    google.type.LatLng lat_lng = 2 [(google.api.field_behavior) = REQUIRED];

    // Required. The radius distance of the area.
    double radius = 3 [(google.api.field_behavior) = REQUIRED];

    // Optional. The unit of the radius.
    RadiusUnits radius_units = 4 [(google.api.field_behavior) = OPTIONAL];
  }

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

  // Optional. The display name of the region.
  optional string display_name = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A list of postal codes that defines the region area.
  PostalCodeArea postal_code_area = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A list of geotargets that defines the region area.
  GeoTargetArea geotarget_area = 4 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Indicates if the region is eligible for use in the Regional
  // Inventory configuration.
  google.protobuf.BoolValue regional_inventory_eligible = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Indicates if the region is eligible for use in the Shipping
  // Services configuration.
  google.protobuf.BoolValue shipping_eligible = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. A radius area that defines the region area.
  RadiusArea radius_area = 7 [(google.api.field_behavior) = OPTIONAL];
}
