// 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";

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 = "DeveloperRegistrationProto";
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 access Developer Registration.
service DeveloperRegistrationService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Registers the GCP used for the API call to the shopping account passed in
  // the request. Will create a user with an "API developer" and add the
  // "developer_email" as a contact with "API notifications" email preference
  // on.
  rpc RegisterGcp(RegisterGcpRequest) returns (DeveloperRegistration) {
    option (google.api.http) = {
      post: "/accounts/v1/{name=accounts/*/developerRegistration}:registerGcp"
      body: "*"
    };
  }

  // Retrieves a developer registration for a merchant.
  rpc GetDeveloperRegistration(GetDeveloperRegistrationRequest)
      returns (DeveloperRegistration) {
    option (google.api.http) = {
      get: "/accounts/v1/{name=accounts/*/developerRegistration}"
    };
    option (google.api.method_signature) = "name";
  }

  // Unregister the calling GCP from the calling shopping account. Note that the
  // GCP will still be able to access the API for at most 1 day from the
  // unregister succussful call.
  rpc UnregisterGcp(UnregisterGcpRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/accounts/v1/{name=accounts/*/developerRegistration}:unregisterGcp"
      body: "*"
    };
  }

  // Retrieves the merchant account that the calling GCP is registered with.
  rpc GetAccountForGcpRegistration(google.protobuf.Empty)
      returns (GetAccountForGcpRegistrationResponse) {
    option (google.api.http) = {
      get: "/accounts/v1/accounts:getAccountForGcpRegistration"
    };
  }
}

// Represents a developer registration owned by a Merchant account.
message DeveloperRegistration {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/DeveloperRegistration"
    pattern: "accounts/{account}/developerRegistration"
    plural: "developerRegistration"
    singular: "developerRegistration"
  };

  // Identifier. The `name` (ID) of the developer registration. Generated by the
  // Content API upon creation of a new `DeveloperRegistration`. The `account`
  // represents the merchant ID of the merchant that owns the registration.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The GCP ids attached to this developer registration
  repeated string gcp_ids = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message for the RegisterGCP method.
message RegisterGcpRequest {
  // Required. The name of the developer registration to be created for the
  // merchant account that the GCP will be registered with. Format:
  // `accounts/{account}/developerRegistration`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/DeveloperRegistration"
    }
  ];

  // Immutable. Optional field. Developer role can be also added by using
  // `users.update` method. If the developer email provided is associated with a
  // user in the provided merchant account, the user will be updated to have
  // `API_DEVELOPER` `access_rights` and the email preference corresponding to
  // that user will be updated to have the new API notifications preference. If
  // the developer email provided is not associated with any user, it is added
  // as a contact. The email preference corresponding to that contact will have
  // the new API notifications preference. Make sure the email used is
  // associated with a Google Account and is not a service account as service
  // accounts can't receive emails.
  string developer_email = 2 [(google.api.field_behavior) = IMMUTABLE];
}

// Request message for the UnregisterGCP method.
message UnregisterGcpRequest {
  // Required. The name of the developer registration to be created for the
  // merchant account that the GCP will be registered with. Format:
  // `accounts/{account}/developerRegistration`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/DeveloperRegistration"
    }
  ];
}

// Request message for the GetDeveloperRegistration method.
message GetDeveloperRegistrationRequest {
  // Required. The `name` (ID) of the developer registration.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/DeveloperRegistration"
    }
  ];
}

// Response message for the GetAccountForGcpRegistration method.
message GetAccountForGcpRegistrationResponse {
  // The name of the merchant account id that the GCP is registered with.
  string name = 1;
}
