// 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.youtube.v1alpha;

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/merchant/youtube/v1alpha/youtube_common.proto";

option csharp_namespace = "Google.Shopping.Merchant.Youtube.V1Alpha";
option go_package = "cloud.google.com/go/shopping/merchant/youtube/apiv1alpha/youtubepb;youtubepb";
option java_multiple_files = true;
option java_outer_classname = "CommissionGroupProto";
option java_package = "com.google.shopping.merchant.youtube.v1alpha";
option php_namespace = "Google\\Shopping\\Merchant\\Youtube\\V1alpha";
option ruby_package = "Google::Shopping::Merchant::Youtube::V1alpha";

// Service to manage YouTube Shopping Affiliate Program commission groups for a
// given contract.
service CommissionGroupService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Retrieves the specified commission group.
  rpc GetCommissionGroup(GetCommissionGroupRequest) returns (CommissionGroup) {
    option (google.api.http) = {
      get: "/youtube/v1alpha/{name=accounts/*/contracts/*/commissionGroups/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists the commission groups for a given contract.
  rpc ListCommissionGroups(ListCommissionGroupsRequest)
      returns (ListCommissionGroupsResponse) {
    option (google.api.http) = {
      get: "/youtube/v1alpha/{parent=accounts/*/contracts/*}/commissionGroups"
    };
    option (google.api.method_signature) = "parent";
  }

  // Creates a new commission group.
  rpc CreateCommissionGroup(CreateCommissionGroupRequest)
      returns (CommissionGroup) {
    option (google.api.http) = {
      post: "/youtube/v1alpha/{parent=accounts/*/contracts/*}/commissionGroups"
      body: "commission_group"
    };
    option (google.api.method_signature) = "parent,commission_group";
  }

  // Updates a given commission group.
  rpc UpdateCommissionGroup(UpdateCommissionGroupRequest)
      returns (CommissionGroup) {
    option (google.api.http) = {
      patch: "/youtube/v1alpha/{commission_group.name=accounts/*/contracts/*/commissionGroups/*}"
      body: "commission_group"
    };
    option (google.api.method_signature) = "commission_group,update_mask";
  }

  // Deletes a given commission group.
  rpc DeleteCommissionGroup(DeleteCommissionGroupRequest)
      returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/youtube/v1alpha/{name=accounts/*/contracts/*/commissionGroups/*}"
    };
    option (google.api.method_signature) = "name";
  }
}

// Youtube Affiliate Program commission group. A commission group defines a
// commission rate and the set of products it applies to.
message CommissionGroup {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/CommissionGroup"
    pattern: "accounts/{account}/contracts/{contract}/commissionGroups/{commission_group}"
    plural: "commissionGroups"
    singular: "commissionGroup"
  };

  // Identifier. The name of the `CommissionGroup` resource.
  // Format:
  // `accounts/{account}/contracts/{contract}/commissionGroups/{commission_group}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. Selects the products that this commission group applies to.
  ProductSelector product_selector = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. Commission that will be paid for conversions that match this
  // commission group.
  CommissionRate commission_rate = 3 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `GetCommissionGroup` method.
message GetCommissionGroupRequest {
  // Required. The name of the commission group to retrieve.
  // Format:
  // `accounts/{account}/contracts/{contract}/commissionGroups/{commission_group}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/CommissionGroup"
    }
  ];
}

// Request message for the `ListCommissionGroups` method.
message ListCommissionGroupsRequest {
  // Required. The contract to list commission groups for.
  // Format: `accounts/{account}/contracts/{contract}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/Contract"
    }
  ];

  // Optional. The maximum number of commission groups to return. The service
  // may return fewer than this value. If unspecified, at most 100 commission
  // groups will be returned. The maximum value is 100; values above 100 will be
  // coerced to 100.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

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

// Response message for the `ListCommissionGroups` method.
message ListCommissionGroupsResponse {
  // The commission groups for the specified contract.
  repeated CommissionGroup commission_groups = 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 `CreateCommissionGroup` method.
message CreateCommissionGroupRequest {
  // Required. The parent contract where this commission group will be created.
  // Format: `accounts/{account}/contracts/{contract}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "merchantapi.googleapis.com/CommissionGroup"
    }
  ];

  // Required. The commission group to create.
  CommissionGroup commission_group = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `UpdateCommissionGroup` method.
message UpdateCommissionGroupRequest {
  // Required. The commission group to update.
  CommissionGroup commission_group = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The list of fields to update.
  //
  // Fields specified in the update mask without a value specified in the
  // body will be deleted from the commission group.
  //
  // If update mask is set to `*`, all fields will be updated.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `DeleteCommissionGroup` method.
message DeleteCommissionGroupRequest {
  // Required. The name of the commission group to delete.
  // Format:
  // `accounts/{account}/contracts/{contract}/commissionGroups/{commission_group}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "merchantapi.googleapis.com/CommissionGroup"
    }
  ];
}

// Selects which products a commission group applies to.
// At least one of the selectors must be set.
message ProductSelector {
  // Optional. Selects products by category.
  CategorySelector category_selector = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// Category selector.
message CategorySelector {
  // Required. The list of categories targeted by this selector.
  // A maximum of 100 is allowed.
  repeated string categories = 1 [(google.api.field_behavior) = REQUIRED];
}
