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

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

option csharp_namespace = "Google.Shopping.Merchant.Quota.V1";
option go_package = "cloud.google.com/go/shopping/merchant/quota/apiv1/quotapb;quotapb";
option java_multiple_files = true;
option java_outer_classname = "AccountLimitsProto";
option java_package = "com.google.shopping.merchant.quota.v1";
option php_namespace = "Google\\Shopping\\Merchant\\Quota\\V1";
option ruby_package = "Google::Shopping::Merchant::Quota::V1";

// Service to retrieve account limits.
service AccountLimitsService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Retrieves an account limit.
  rpc GetAccountLimit(GetAccountLimitRequest) returns (AccountLimit) {
    option (google.api.http) = {
      get: "/accounts/v1/{name=accounts/*/limits/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists the limits of an account.
  rpc ListAccountLimits(ListAccountLimitsRequest)
      returns (ListAccountLimitsResponse) {
    option (google.api.http) = {
      get: "/accounts/v1/{parent=accounts/*}/limits"
    };
    option (google.api.method_signature) = "parent";
  }
}

// The limit for products.
message ProductLimit {
  // The scope of the limit.
  enum Scope {
    // Default value. Should not be used.
    SCOPE_UNSPECIFIED = 0;

    // Limit for products in non-EEA countries.
    ADS_NON_EEA = 1;

    // Limit for products in EEA countries.
    ADS_EEA = 2;
  }

  // Required. The scope of the product limit.
  Scope scope = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The maximum number of products that are allowed in the account in
  // the given scope.
  int64 limit = 2 [(google.api.field_behavior) = REQUIRED];
}

// A limit of a certain type that is applied to an account.
message AccountLimit {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/AccountLimit"
    pattern: "accounts/{account}/limits/{limit}"
    plural: "accountLimits"
    singular: "accountLimit"
  };

  // The type of the limit.
  oneof type {
    // The limit for products.
    ProductLimit products = 100;
  }

  // Identifier. The limit part of the name will be a combination of the type
  // and the scope. For example: `accounts/123/limits/products~ADS_NON_EEA`
  //
  // Format: `accounts/{account}/limits/{limit}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];
}

// Request message for the `GetAccountLimit` method.
message GetAccountLimitRequest {
  // Required. The name of the limit to retrieve.
  // Format: `accounts/{account}/limits/{limit}`
  // For example: `accounts/123/limits/products~ADS_NON_EEA`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/AccountLimit"
    }
  ];
}

// Request message for the `ListAccountLimits` method.
message ListAccountLimitsRequest {
  // Required. The parent account.
  // 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 limits to return. The service may return
  // fewer than this value. If unspecified, at most 100 limits will be returned.
  // The maximum value is 100; values above 100 will be coerced to 100.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

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

  // Required. A filter on the limit `type` is required, for example, `type =
  // "products"`.
  string filter = 4 [(google.api.field_behavior) = REQUIRED];
}

// Response message for the `ListAccountLimits` method.
message ListAccountLimitsResponse {
  // The limits for the given account.
  repeated AccountLimit account_limits = 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;
}
