// Copyright 2018 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.


// Proto file describing the Recommendation service.
syntax = "proto3";

package google.ads.googleads.v0.services;

import "google/ads/googleads/v0/common/ad.proto";
import "google/ads/googleads/v0/enums/keyword_match_type.proto";
import "google/ads/googleads/v0/resources/recommendation.proto";
import "google/api/annotations.proto";
import "google/protobuf/wrappers.proto";
import "google/rpc/status.proto";

option java_package = "com.google.ads.googleads.v0.services";
option java_outer_classname = "RecommendationServiceProto";
option java_multiple_files = true;

// Objective-C prefix. Google Ads API.
option objc_class_prefix = "GAA";
option csharp_namespace = "Google.Ads.GoogleAds.V0.Services";
option php_namespace = "Google\\Ads\\GoogleAds\\V0\\Services";
option php_metadata_namespace = "Google\\Ads\\GoogleAds\\V0\\Services";

// Service to manage recommendations.
service RecommendationService {
  // Returns the requested recommendation in full detail.
  rpc GetRecommendation(GetRecommendationRequest)
      returns (resources.Recommendation) {
    option (google.api.http) = {
      get: "/v0/{resource_name=customers/*/recommendations/*}"
    };
  }

  // Applies given recommendations with corresponding apply parameters.
  rpc ApplyRecommendation(ApplyRecommendationRequest)
      returns (ApplyRecommendationResponse) {
    option (google.api.http) = {
      post: "/v0/customers/{customer_id=*}/recommendations:apply"
      body: "*"
    };
  }
}

// Request message for [RecommendationService.GetRecommendation][].
message GetRecommendationRequest {
  // The resource name of the recommendation to fetch.
  string resource_name = 1;
}

// Request message for [RecommendationService.ApplyRecommendation][].
message ApplyRecommendationRequest {
  // The ID of the customer with the recommendation.
  string customer_id = 1;

  // The list of operations to apply recommendations.
  repeated ApplyRecommendationOperation operations = 2;
}

// Information about the operation to apply a recommendation and any parameters
// to
// customize it.
message ApplyRecommendationOperation {
  // The resource name of the recommendation to apply.
  string resource_name = 1;

  // Parameters to use when applying the recommendation.
  oneof apply_parameters {
    // Optional parameters to use when applying a campaign budget
    // recommendation.
    CampaignBudgetParameters campaign_budget = 2;

    // Optional parameters to use when applying a text ad recommendation.
    TextAdParameters text_ad = 3;

    // Optional parameters to use when applying keyword recommendation.
    KeywordParameters keyword = 4;

    // Optional parameters to use when applying target CPA opt-in
    // recommendation.
    TargetCpaOptInParameters target_cpa_opt_in = 5;
  }

  // Parameters to use when applying a campaign budget recommendation.
  message CampaignBudgetParameters {
    // New budget amount to set for target budget resource. This is a required
    // field.
    google.protobuf.Int64Value new_budget_amount_micros = 1;
  }

  // Parameters to use when applying a text ad recommendation.
  message TextAdParameters {
    // New ad to add to recommended ad group. All necessary fields need to be
    // set in this message. This is a required field.
    common.Ad ad = 1;
  }

  // Parameters to use when applying keyword recommendation.
  message KeywordParameters {
    // The ad group resource to add keyword to. This is a required field.
    google.protobuf.StringValue ad_group = 1;

    // The match type of the keyword. This is a required field.
    enums.KeywordMatchTypeEnum.KeywordMatchType match_type = 2;

    // Optional, CPC bid to set for the keyword. If not set, keyword will use
    // bid based on bidding strategy used by target ad group.
    google.protobuf.Int64Value cpc_bid_micros = 3;
  }

  // Parameters to use when applying Target CPA recommendation.
  message TargetCpaOptInParameters {
    // Average CPA to use for Target CPA bidding strategy. This is a required
    // field.
    google.protobuf.Int64Value target_cpa_micros = 1;

    // Optional, budget amount to set for the campaign.
    google.protobuf.Int64Value new_campaign_budget_amount_micros = 2;
  }
}

// Response message for [RecommendationService.ApplyRecommendation][].
message ApplyRecommendationResponse {
  // Results of operations to apply recommendations.
  repeated ApplyRecommendationResult results = 1;
}

// The result of applying a recommendation.
message ApplyRecommendationResult {
  // One of the successfully applied recommendation resource name or error
  // information will be set.
  oneof result {
    // Returned for successful applies.
    string resource_name = 1;

    // Returned for failed operations.
    google.rpc.Status status = 2;
  }
}
