// 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.issueresolution.v1beta;

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

option csharp_namespace = "Google.Shopping.Merchant.IssueResolution.V1Beta";
option go_package = "cloud.google.com/go/shopping/merchant/issueresolution/apiv1beta/issueresolutionpb;issueresolutionpb";
option java_multiple_files = true;
option java_outer_classname = "AggregateProductStatusesProto";
option java_package = "com.google.shopping.merchant.issueresolution.v1beta";
option php_namespace = "Google\\Shopping\\Merchant\\IssueResolution\\V1beta";
option ruby_package = "Google::Shopping::Merchant::IssueResolution::V1beta";

// Service to manage aggregate product statuses.
service AggregateProductStatusesService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Lists the `AggregateProductStatuses` resources for your merchant account.
  // The response might contain fewer items than specified by `pageSize`.
  // If `pageToken` was returned in previous request, it can be used to obtain
  // additional results.
  rpc ListAggregateProductStatuses(ListAggregateProductStatusesRequest)
      returns (ListAggregateProductStatusesResponse) {
    option (google.api.http) = {
      get: "/issueresolution/v1beta/{parent=accounts/*}/aggregateProductStatuses"
    };
    option (google.api.method_signature) = "parent";
  }
}

// Request message for the `ListAggregateProductStatuses` method.
message ListAggregateProductStatusesRequest {
  // Required. The account to list aggregate product statuses for.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "merchantapi.googleapis.com/AggregateProductStatus"
    }
  ];

  // Optional. The maximum number of aggregate product statuses to return. The
  // service may return fewer than this value. If unspecified, at most 25
  // aggregate product statuses are returned. The maximum value is 250; values
  // above 250 are coerced to 250.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

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

  // Optional. A filter expression that filters the aggregate product statuses.
  // Filtering is only supported by the `reporting_context` and `country` field.
  // For example: `reporting_context = "SHOPPING_ADS" AND country = "US"`.
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for the `ListAggregateProductStatuses` method.
message ListAggregateProductStatusesResponse {
  // The `AggregateProductStatuses` resources for the given account.
  repeated AggregateProductStatus aggregate_product_statuses = 1;

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

// Aggregate product statuses for a given reporting context and country.
message AggregateProductStatus {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/AggregateProductStatus"
    pattern: "accounts/{account}/aggregateProductStatuses/{aggregate_product_status}"
    plural: "aggregateProductStatuses"
    singular: "aggregateProductStatus"
  };

  // Products statistics.
  message Stats {
    // The number of products that are active.
    int64 active_count = 1;

    // The number of products that are pending.
    int64 pending_count = 2;

    // The number of products that are disapproved.
    int64 disapproved_count = 3;

    // The number of products that are expiring.
    int64 expiring_count = 4;
  }

  // The ItemLevelIssue of the product status.
  message ItemLevelIssue {
    // How the issue affects the serving of the product.
    enum Severity {
      // Not specified.
      SEVERITY_UNSPECIFIED = 0;

      // This issue represents a warning and does not have a direct affect
      // on the product.
      NOT_IMPACTED = 1;

      // The product is demoted and most likely have limited performance
      // in search results
      DEMOTED = 2;

      // Issue disapproves the product.
      DISAPPROVED = 3;
    }

    // How the issue can be resolved.
    enum Resolution {
      // Not specified.
      RESOLUTION_UNSPECIFIED = 0;

      // The issue can be resolved by the merchant.
      MERCHANT_ACTION = 1;

      // The issue will be resolved auomatically.
      PENDING_PROCESSING = 2;
    }

    // The error code of the issue.
    string code = 1;

    // How this issue affects serving of the offer.
    Severity severity = 2;

    // Whether the issue can be resolved by the merchant.
    Resolution resolution = 3;

    // The attribute's name, if the issue is caused by a single attribute.
    string attribute = 4;

    // A short issue description in English.
    string description = 6;

    // A detailed issue description in English.
    string detail = 7;

    // The URL of a web page to help with resolving this issue.
    string documentation_uri = 8;

    // The number of products affected by this issue.
    int64 product_count = 9;
  }

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

  // The reporting context of the aggregate product statuses.
  google.shopping.type.ReportingContext.ReportingContextEnum reporting_context =
      3;

  // The country of the aggregate product statuses. Represented as a
  // [CLDR territory
  // code](https://github.com/unicode-org/cldr/blob/latest/common/main/en.xml).
  string country = 4;

  // Products statistics for the given reporting context and country.
  Stats stats = 5;

  // The product issues that affect the given reporting context and country.
  repeated ItemLevelIssue item_level_issues = 6;
}
