// 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";
import "google/protobuf/field_mask.proto";
import "google/shopping/type/types.proto";

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

// Service for supporting [checkout
// settings](https://support.google.com/merchants/answer/13945960).
service CheckoutSettingsService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Gets `CheckoutSettings` for the given merchant. This includes
  // information about review state, enrollment state and URL settings.
  rpc GetCheckoutSettings(GetCheckoutSettingsRequest)
      returns (CheckoutSettings) {
    option (google.api.http) = {
      get: "/accounts/v1beta/{name=accounts/*/programs/*/checkoutSettings}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates `CheckoutSettings` for the given merchant.
  rpc CreateCheckoutSettings(CreateCheckoutSettingsRequest)
      returns (CheckoutSettings) {
    option (google.api.http) = {
      post: "/accounts/v1beta/{parent=accounts/*/programs/*}/checkoutSettings"
      body: "checkout_settings"
    };
    option (google.api.method_signature) = "parent,checkout_settings";
  }

  // Updates `CheckoutSettings` for the given merchant.
  rpc UpdateCheckoutSettings(UpdateCheckoutSettingsRequest)
      returns (CheckoutSettings) {
    option (google.api.http) = {
      patch: "/accounts/v1beta/{checkout_settings.name=accounts/*/programs/*/checkoutSettings}"
      body: "checkout_settings"
    };
    option (google.api.method_signature) = "checkout_settings,update_mask";
  }

  // Deletes `CheckoutSettings` and unenrolls merchant from
  // `Checkout` program.
  rpc DeleteCheckoutSettings(DeleteCheckoutSettingsRequest)
      returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/accounts/v1beta/{name=accounts/*/programs/*/checkoutSettings}"
    };
    option (google.api.method_signature) = "name";
  }
}

// Request message for `GetCheckoutSettings` method.
message GetCheckoutSettingsRequest {
  // Required. The name/identifier of the merchant account.
  // Format: `accounts/{account}/programs/{program}/checkoutSettings`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/CheckoutSettings"
    }
  ];
}

// Request message for the `CreateCheckoutSettings` method.
message CreateCheckoutSettingsRequest {
  // Required. The merchant account for which the `CheckoutSettings` will be
  // created.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "merchantapi.googleapis.com/CheckoutSettings"
    }
  ];

  // Required. The `CheckoutSettings` object to create.
  CheckoutSettings checkout_settings = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `UpdateCheckoutSettings` method.
message UpdateCheckoutSettingsRequest {
  // Required. The updated version of the `CheckoutSettings`.
  // The `name` field is used to identify the `CheckoutSettings`.
  // Format: `accounts/{account}/programs/{program}/checkoutSettings`
  CheckoutSettings checkout_settings = 1
      [(google.api.field_behavior) = REQUIRED];

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

// Request message for the `DeleteCheckoutSettings` method.
message DeleteCheckoutSettingsRequest {
  // Required. The name/identifier of the merchant account.
  // Format: `accounts/{account}/programs/{program}/checkoutSettings`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/CheckoutSettings"
    }
  ];
}

// [CheckoutSettings](https://support.google.com/merchants/answer/13945960) for
// a specific merchant.
message CheckoutSettings {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/CheckoutSettings"
    pattern: "accounts/{account}/programs/{program}/checkoutSettings"
    plural: "settings"
    singular: "checkoutSettings"
  };

  // Enum indicating the enrollment state of merchant in `Checkout`
  // program.
  enum CheckoutEnrollmentState {
    // Default enrollment state when enrollment state is not specified.
    CHECKOUT_ENROLLMENT_STATE_UNSPECIFIED = 0;

    // Merchant has not enrolled into the program.
    INACTIVE = 1;

    // Merchant has enrolled into the program by providing either an
    // account level URL or checkout URLs as part of their feed.
    ENROLLED = 2;

    // Merchant has previously enrolled but opted out of the program.
    OPTED_OUT = 3;
  }

  // Enum indicating the review state of merchant in `Checkout`
  // program.
  enum CheckoutReviewState {
    // Default review state when review state is not specified.
    CHECKOUT_REVIEW_STATE_UNSPECIFIED = 0;

    // Merchant provided URLs are being reviewed for data quality issues.
    IN_REVIEW = 1;

    // Merchant account has been approved. Indicates the data quality checks
    // have passed.
    APPROVED = 2;

    // Merchant account has been disapproved due to data quality issues.
    DISAPPROVED = 3;
  }

  // Identifier. The resource name of the program configuration settings.
  // Format: `accounts/{account}/programs/{program}/checkoutSettings`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // URI settings for cart or checkout URL.
  optional UriSettings uri_settings = 2;

  // Optional. The destinations to which the checkout program applies, valid
  // destination values are `SHOPPING_ADS`, `FREE_LISTINGS`
  repeated google.shopping.type.Destination.DestinationEnum
      eligible_destinations = 8 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Reflects the merchant enrollment state in `Checkout` program.
  optional CheckoutEnrollmentState enrollment_state = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Reflects the merchant review state in `Checkout` program.
  // This is set based on the data quality reviews of the URL provided by
  // the merchant.
  // A merchant with enrollment state
  // as `ENROLLED` can be in the following review states: `IN_REVIEW`,
  // `APPROVED` or `DISAPPROVED`. A merchant must be in an `enrollment_state` of
  // `ENROLLED` before a review can begin for the merchant.For more details,
  // check the help center doc.
  optional CheckoutReviewState review_state = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The effective value of `uri_settings` for a given merchant. If
  // account level settings are present then this value will be a copy of url
  // settings. Otherwise, it will have the value of the parent account (for only
  // marketplace sellers).
  UriSettings effective_uri_settings = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The effective value of enrollment_state for a given merchant
  // ID. If account level settings are present then this value will be a copy of
  // the account level settings. Otherwise, it will have the value of the parent
  // account (for only marketplace sellers).
  optional CheckoutEnrollmentState effective_enrollment_state = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The effective value of `review_state` for a given merchant ID.
  // If account level settings are present then this value will be a copy of the
  // account level settings. Otherwise, it will have the value of the parent
  // account (for only marketplace sellers).
  optional CheckoutReviewState effective_review_state = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// URL settings for cart or checkout URL.
message UriSettings {
  // Specifications related to the `Checkout` URL. The `UriTemplate` is
  // of the form `https://www.mystore.com/checkout?item_id={id}`
  // where `{id}` will be automatically replaced with [offer_id]
  // (https://developers.google.com/shopping-content/reference/rest/v2.1/products#Product.FIELDS.offer_id)
  // attribute from the merchant account
  oneof uri_template {
    // Checkout URL template. When the placeholders are expanded will redirect
    // the buyer to the merchant checkout page with the item in the cart. For
    // more details, check the [help center
    // doc](https://support.google.com/merchants/answer/13945960#method1&zippy=%2Cproduct-level-url-formatting%2Caccount-level-url-formatting)
    string checkout_uri_template = 1;

    // Cart URL template. When the placeholders are expanded will redirect the
    // buyer to the cart page on the merchant website with the selected
    // item in cart. For more details, check the [help center
    // doc](https://support.google.com/merchants/answer/13945960#method1&zippy=%2Cproduct-level-url-formatting%2Caccount-level-url-formatting)
    string cart_uri_template = 2;
  }
}
