// 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/field_mask.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 = "AccountRelationshipsProto";
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";

// Service to support AccountRelationship API.
service AccountRelationshipsService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Retrieve an account relationship.
  rpc GetAccountRelationship(GetAccountRelationshipRequest)
      returns (AccountRelationship) {
    option (google.api.http) = {
      get: "/accounts/v1/{name=accounts/*/relationships/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Updates the account relationship. Executing this method requires admin
  // access.
  rpc UpdateAccountRelationship(UpdateAccountRelationshipRequest)
      returns (AccountRelationship) {
    option (google.api.http) = {
      patch: "/accounts/v1/{account_relationship.name=accounts/*/relationships/*}"
      body: "account_relationship"
    };
    option (google.api.method_signature) = "account_relationship,update_mask";
  }

  // List account relationships for the specified account.
  rpc ListAccountRelationships(ListAccountRelationshipsRequest)
      returns (ListAccountRelationshipsResponse) {
    option (google.api.http) = {
      get: "/accounts/v1/{parent=accounts/*}/relationships"
    };
    option (google.api.method_signature) = "parent";
  }
}

// The `AccountRelationship` message defines a formal connection between a
// merchant's account and a service provider's account. This relationship
// enables the provider to offer specific services to the business, such as
// product management or campaign management. It specifies the access rights
// and permissions to the business's data relevant to those services.
//
// Establishing an account relationship involves linking the merchant's account
// with a provider's account. The provider could be another Google account (like
// Google Ads or Google My Business) or a third-party platform (such as Shopify
// or WooCommerce).
message AccountRelationship {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/AccountRelationship"
    pattern: "accounts/{account}/relationships/{relationship}"
    plural: "accountRelationships"
    singular: "accountRelationship"
  };

  // Identifier. The resource name of the account relationship.
  // Format: `accounts/{account}/relationships/{relationship}`. For example,
  // `accounts/123456/relationships/567890`.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Immutable. The provider of the service. Either the reference to an account
  // such as `providers/123` or a well-known service provider (one of
  // `providers/GOOGLE_ADS` or `providers/GOOGLE_BUSINESS_PROFILE`).
  optional string provider = 2 [(google.api.field_behavior) = IMMUTABLE];

  // Output only. The human-readable display name of the provider account.
  string provider_display_name = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. An optional alias you can assign to this account relationship.
  // This alias acts as a convenient identifier for your own reference and
  // management. It must be unique among all your account relationships with the
  // same provider.
  //
  // For example, you might use `account_id_alias` to assign a friendly name
  // to this relationship for easier identification in your systems.
  string account_id_alias = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Request to get an account relationship.
message GetAccountRelationshipRequest {
  // Required. The resource name of the account relationship to get.
  // Format: `accounts/{account}/relationships/{relationship}`. For example,
  // `accounts/123456/relationships/567890`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/AccountRelationship"
    }
  ];
}

// Request message for the `UpdateAccountRelationship` method.
message UpdateAccountRelationshipRequest {
  // Required. The new version of the account relationship.
  AccountRelationship account_relationship = 1
      [(google.api.field_behavior) = REQUIRED];

  // Optional. List of fields being updated.
  //
  // The following fields are supported (in both `snake_case` and
  // `lowerCamelCase`):
  //
  // - `account_id_alias`
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// Request to list account relationships.
message ListAccountRelationshipsRequest {
  // Required. The parent account of the account relationship to filter by.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Account"
    }
  ];

  // Optional. The token returned by the previous `list` request.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum number of elements to return in the response. Use for
  // paging. If no `page_size` is specified, `100` is used as the default value.
  // The maximum allowed value is `1000`.
  int32 page_size = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response after trying to list account relationships.
message ListAccountRelationshipsResponse {
  // The account relationships that match your filter.
  repeated AccountRelationship account_relationships = 1;

  // A page token. You can send the `page_token` to get the next page.
  // Only included in the `list` response if there are more pages.
  string next_page_token = 2;
}
