// 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/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 = "ContractProto";
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";
option (google.api.resource_definition) = {
  type: "merchantapi.googleapis.com/Account"
  pattern: "accounts/{account}"
};

// Service to manage YouTube Shopping Affiliate Program contracts.
service ContractService {
  option (google.api.default_host) = "merchantapi.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/content";

  // Retrieves the specified contract.
  rpc GetContract(GetContractRequest) returns (Contract) {
    option (google.api.http) = {
      get: "/youtube/v1alpha/{name=accounts/*/contracts/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists the contracts for a given account.
  rpc ListContracts(ListContractsRequest) returns (ListContractsResponse) {
    option (google.api.http) = {
      get: "/youtube/v1alpha/{parent=accounts/*}/contracts"
    };
    option (google.api.method_signature) = "parent";
  }

  // Creates a new contract.
  rpc CreateContract(CreateContractRequest) returns (Contract) {
    option (google.api.http) = {
      post: "/youtube/v1alpha/{parent=accounts/*}/contracts"
      body: "contract"
    };
    option (google.api.method_signature) = "parent,contract";
  }

  // Updates a given contract.
  rpc UpdateContract(UpdateContractRequest) returns (Contract) {
    option (google.api.http) = {
      patch: "/youtube/v1alpha/{contract.name=accounts/*/contracts/*}"
      body: "contract"
    };
    option (google.api.method_signature) = "contract,update_mask";
  }
}

// Youtube Affiliate Program contract. Contains information about the commission
// rates applied to creators in the program.
message Contract {
  option (google.api.resource) = {
    type: "merchantapi.googleapis.com/Contract"
    pattern: "accounts/{account}/contracts/{contract}"
    plural: "contracts"
    singular: "contract"
  };

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

  // Required. The default commission rate for the contract.
  CommissionRate default_commission = 2
      [(google.api.field_behavior) = REQUIRED];
}

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

// Request message for the `ListContracts` method.
message ListContractsRequest {
  // Required. The account to list contracts for.
  // 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 contracts to return. The service may return
  // fewer than this value. If unspecified, at most 100 contracts 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 `ListContracts` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListContracts`
  // must match the call that provided the page token.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for the `ListContracts` method.
message ListContractsResponse {
  // The contracts for the specified account.
  repeated Contract contracts = 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 `CreateContract` method.
message CreateContractRequest {
  // Required. The parent account where this contract will be created.
  // Format: `accounts/{account}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "merchantapi.googleapis.com/Contract"
    }
  ];

  // Required. The contract to create.
  Contract contract = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `UpdateContract` method.
message UpdateContractRequest {
  // Required. The contract to update.
  Contract contract = 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 contract.
  //
  // If update mask is set to `*`, all fields will be updated.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}
