// 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/empty.proto";

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

// The service facilitates the management of a merchant's Google Business
// Profile (GBP) account settings. This API defines the following resource
// model:
// - [GbpAccount][google.shopping.merchant.accounts.v1.GbpAccount]
service GbpAccountsService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // List the GBP accounts for a given merchant.
  rpc ListGbpAccounts(ListGbpAccountsRequest)
      returns (ListGbpAccountsResponse) {
    option (google.api.http) = {
      get: "/accounts/v1beta/{parent=accounts/*}/gbpAccounts"
    };
    option (google.api.method_signature) = "parent";
  }

  // Link the specified merchant to a GBP account for all countries.
  rpc LinkGbpAccount(LinkGbpAccountRequest) returns (LinkGbpAccountResponse) {
    option (google.api.http) = {
      post: "/accounts/v1beta/{parent=accounts/*}/gbpAccounts:linkGbpAccount"
      body: "*"
    };
    option (google.api.method_signature) = "parent";
  }
}

// Collection of information related to a Google Business Profile (GBP) account.
message GbpAccount {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/GbpAccount"
    pattern: "accounts/{account}/gbpAccounts/{gbp_account}"
    plural: "gbpAccounts"
    singular: "gbpAccount"
  };

  // The type of the GBP account.
  enum Type {
    // Default value. This value is unused.
    TYPE_UNSPECIFIED = 0;

    // The GBP account is a user account.
    USER = 1;

    // The GBP account is a business account.
    BUSINESS_ACCOUNT = 2;
  }

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

  // The id of the GBP account.
  string gbp_account_id = 2;

  // The type of the Business Profile.
  Type type = 3;

  // The name of the Business Profile.
  // For personal accounts: Email id of the owner.
  // For Business accounts: Name of the Business Account.
  string gbp_account_name = 5;

  // Number of listings under this account.
  int64 listing_count = 6;
}

// Request message for the ListGbpAccounts method.
message ListGbpAccountsRequest {
  // Required. The name of the parent resource under which the GBP accounts are
  // listed. 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 `GbpAccount` resources to return. The
  // service returns fewer than this value if the number of gbp accounts is less
  // that than the `pageSize`. The default value is 50. The maximum value is
  // 1000; If a value higher than the maximum is specified, then the `pageSize`
  // will default to the maximum.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

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

// Response message for the ListGbpAccounts method.
message ListGbpAccountsResponse {
  // The GBP accounts from the specified merchant in the specified country.
  repeated GbpAccount gbp_accounts = 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;
}

// Request message for the LinkGbpAccount method.
message LinkGbpAccountRequest {
  // Required. The name of the parent resource to which the GBP account is
  // linked. Format: `accounts/{account}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Required. The email address of the Business Profile account.
  string gbp_email = 2 [(google.api.field_behavior) = REQUIRED];
}

// Response message for the LinkGbpAccount method.
message LinkGbpAccountResponse {
  // Empty response.
  google.protobuf.Empty response = 1;
}
