// 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.ads.admanager.v1;

import "google/ads/admanager/v1/ad_rule_enums.proto";
import "google/ads/admanager/v1/ad_rule_slot_behavior_enum.proto";
import "google/ads/admanager/v1/ad_rule_slot_bumper_enum.proto";
import "google/ads/admanager/v1/ad_rule_slot_midroll_frequency_type_enum.proto";
import "google/ads/admanager/v1/targeting.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Ads.AdManager.V1";
option go_package = "google.golang.org/genproto/googleapis/ads/admanager/v1;admanager";
option java_multiple_files = true;
option java_outer_classname = "AdRuleMessagesProto";
option java_package = "com.google.ads.admanager.v1";
option php_namespace = "Google\\Ads\\AdManager\\V1";
option ruby_package = "Google::Ads::AdManager::V1";

// An AdRule contains data that the ad server will use to generate a playlist of
// video ads.
message AdRule {
  option (google.api.resource) = {
    type: "admanager.googleapis.com/AdRule"
    pattern: "networks/{network_code}/adRules/{ad_rule}"
    plural: "adRules"
    singular: "adRule"
  };

  // Identifier. The resource name of the `AdRule`.
  // Format: `networks/{network_code}/adRules/{ad_rule_id}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. The unique name of the AdRule. This attribute is required to
  // create an ad rule and has a maximum length of 255 characters.
  optional string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. The priority of the AdRule. This attribute is required and can
  // range from 1 to 1000, with 1 being the highest possible priority.
  //
  // Changing an ad rule's priority can affect the priorities of other ad rules.
  // For example,
  // increasing an ad rule's priority from 5 to 1 will shift the ad rules that
  // were previously in
  // priority positions 1 through 4 down one.
  optional int32 priority = 3 [(google.api.field_behavior) = OPTIONAL];

  // Required. The start time of the AdRule. This attribute is required and must
  // be a date in the future for new ad rules.
  optional google.protobuf.Timestamp start_time = 13
      [(google.api.field_behavior) = REQUIRED];

  // Optional. This end time of the AdRule. This attribute is required
  // unless
  // [end_time_unlimited][google.ads.admanager.v1.AdRule.end_time_unlimited] is
  // set to true. If specified, it must be after the
  // [start_time][google.ads.admanager.v1.AdRule.start_time].
  optional google.protobuf.Timestamp end_time = 14
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Specifies whether or not the AdRule has an end time. This
  // attribute is optional and defaults to false.
  optional bool end_time_unlimited = 15
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. The AdRuleStatus of the AdRule. This attribute is read-only
  // and defaults to [AdRuleStatus.INACTIVE][].
  optional AdRuleStatusEnum.AdRuleStatus status = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The FrequencyCapBehavior of the AdRule. This attribute is
  // optional and defaults to [FrequencyCapBehavior.DEFER][].
  optional AdRuleFrequencyCapBehaviorEnum.AdRuleFrequencyCapBehavior
      frequency_cap_behavior = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. This AdRule object's frequency cap for the maximum impressions
  // per stream. This attribute is optional and defaults to 0.
  optional int32 max_impressions_per_line_item_per_stream = 6
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. This AdRule object's frequency cap for the maximum impressions
  // per pod. This attribute is optional and defaults to 0.
  optional int32 max_impressions_per_line_item_per_pod = 7
      [(google.api.field_behavior) = OPTIONAL];

  // Required. This AdRule object's pre-roll slot. This attribute is required.
  optional AdRuleSlot preroll = 8 [(google.api.field_behavior) = REQUIRED];

  // Required. This AdRule object's video mid-roll slots. This attribute is
  // required, and there must be at least one mid-roll.
  repeated AdRuleSlot midrolls = 9 [(google.api.field_behavior) = REQUIRED];

  // Required. This AdRule object's post-roll slot. This attribute is required.
  optional AdRuleSlot postroll = 10 [(google.api.field_behavior) = REQUIRED];

  // Required. The targeting of the `AdRule`.
  optional Targeting targeting = 11 [(google.api.field_behavior) = REQUIRED];
}

// Simple object representing an ad slot within an AdRule. Ad rule slots contain
// information about the types/number of ads to display, as well as additional
// information on how the ad server will generate playlists.
message AdRuleSlot {
  // Optional. The AdRuleSlotBehavior for video ads for this slot. This
  // attribute is optional and defaults to [AdRuleSlotBehavior.DEFER][].
  // Indicates whether video ads are allowed for this slot, or if the decision
  // is deferred to alower-priority ad rule.
  optional AdRuleSlotBehaviorEnum.AdRuleSlotBehavior slot_behavior = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum duration in milliseconds of video ads within this
  // slot. This attribute is optional and defaults to 0.
  optional google.protobuf.Duration max_video_ad_duration = 4
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The frequency type for video ads in this ad rule slot. This
  // attribute is required for mid-rolls, but if this is not a mid-roll, the
  // value is set to [AdRuleSlotMidrollFrequencyType.NONE][].
  optional AdRuleSlotMidrollFrequencyTypeEnum.AdRuleSlotMidrollFrequencyType
      video_midroll_frequency_type = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The mid-roll frequency of this ad rule slot for video ads. This
  // attribute is required for mid-rolls, but if MidrollFrequencyType is set to
  // [AdRuleSlotMidrollFrequencyType.NONE][], this value should be ignored. For
  // example, if this slot has a frequency type of
  // [AdRuleSlotMidrollFrequencyType.EVERY_N_SECONDS][] and
  // # videoMidrollFrequency = "60", this would mean "play a mid-roll every 60
  //
  // seconds."
  optional string video_midroll_frequency = 6
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The AdRuleSlotBumper for this slot. This attribute is optional
  // and defaults to [AdRuleSlotBumper.NONE][].
  optional AdRuleSlotBumperEnum.AdRuleSlotBumper bumper = 7
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum duration of bumper ads within this slot. This
  // attribute is optional and defaults to 0.
  optional google.protobuf.Duration max_bumper_duration = 8
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum pod duration for this slot. This attribute is
  // optional and defaults to 0.
  optional google.protobuf.Duration max_pod_duration = 9
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum number of ads allowed in a pod in this slot. This
  // attribute is optional and defaults to 0.
  optional int32 pod_max_ad_count = 10 [(google.api.field_behavior) = OPTIONAL];
}
