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

import "google/ads/admanager/v1/request_platform_enum.proto";
import "google/ads/admanager/v1/targeted_video_bumper_type_enum.proto";
import "google/ads/admanager/v1/video_position_enum.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.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 = "TargetingProto";
option java_package = "com.google.ads.admanager.v1";
option php_namespace = "Google\\Ads\\AdManager\\V1";
option ruby_package = "Google::Ads::AdManager::V1";

// Targeting expression.
//
message Targeting {
  // Optional. Used to target/exclude various geo targets.
  GeoTargeting geo_targeting = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target various technology targeting dimensions.
  TechnologyTargeting technology_targeting = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target/exclude various ad units and/or placements.
  InventoryTargeting inventory_targeting = 5
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target specific request platforms.
  RequestPlatformTargeting request_platform_targeting = 6
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target key/values, audience segments, and/or CMS
  // metadata.
  CustomTargeting custom_targeting = 7 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target user domains.
  UserDomainTargeting user_domain_targeting = 10
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target video positions.
  VideoPositionTargeting video_position_targeting = 12
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Used to target data segments.
  DataSegmentTargeting data_segment_targeting = 13
      [(google.api.field_behavior) = OPTIONAL];
}

// Represents a list of targeted and excluded geos.
message GeoTargeting {
  // Optional. A list of geo resource names that should be targeted/included.
  repeated string targeted_geos = 3 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/GeoTarget"
    }
  ];

  // Optional. A list of geo resource names that should be excluded.
  repeated string excluded_geos = 4 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/GeoTarget"
    }
  ];
}

// Various types of technology targeting expressed by child messages are
// applied with logical AND.
message TechnologyTargeting {
  // Optional. Bandwidth targeting dimension.
  BandwidthTargeting bandwidth_targeting = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Device category targeting dimension.
  DeviceCategoryTargeting device_category_targeting = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Operating system targeting dimension.
  OperatingSystemTargeting operating_system_targeting = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// Bandwidth Targeting.
//
// Reach users accessing the internet via various means of connection, such as
// cable, DSL, or dial-up. Can be useful to target campaigns using
// low-resolution creatives or text ads for users with low bandwidth.
message BandwidthTargeting {
  // Optional. A list of resource names of the bandwidth groups that should be
  // targeted/included.
  repeated string targeted_bandwidth_groups = 3 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/BandwidthGroup"
    }
  ];

  // Optional. A list of resource names of the bandwidth groups that should be
  // excluded.
  repeated string excluded_bandwidth_groups = 4 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/BandwidthGroup"
    }
  ];
}

// Represents a list of targeted and excluded device categories.
message DeviceCategoryTargeting {
  // Optional. A list of device category resource names that should be
  // targeted/included.
  repeated string targeted_categories = 3 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/DeviceCategory"
    }
  ];

  // Optional. A list of device category resource names that should be excluded.
  repeated string excluded_categories = 4 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/DeviceCategory"
    }
  ];
}

// Operating System Targeting
message OperatingSystemTargeting {
  // Optional. A list of operating system resource names that should be
  // targeted/included.
  repeated string targeted_operating_systems = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/OperatingSystem"
    }
  ];

  // Optional. A list of operating system resource names that should be
  // excluded.
  repeated string excluded_operating_systems = 6 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/OperatingSystem"
    }
  ];

  // Optional. A list of operating system version resource names that should be
  // targeted/included.
  repeated string targeted_operating_system_versions = 7 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/OperatingSystemVersion"
    }
  ];

  // Optional. A list of operating system version resource names that should be
  // excluded.
  repeated string excluded_operating_system_versions = 8 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/OperatingSystemVersion"
    }
  ];
}

// Targeted ad units and AU placements are applied with
// logical OR. Example:
//
//  (au:1 OR au:2 OR au_placement:5) AND (NOT (au:3))
message InventoryTargeting {
  // Optional. A list of ad units that should be targeted/included.
  repeated AdUnitTargeting targeted_ad_units = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. A list of ad units that should be excluded.
  //
  // Excluded AUs take precedence over targeted AUs. In fact an AU can be
  // excluded only if one of its ancestors is targeted. Subsequently child
  // AUs of an excluded AU can not be targeted (except via a placement).
  repeated AdUnitTargeting excluded_ad_units = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The resource names of the placements that should be
  // targeted/included.
  repeated string targeted_placements = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/Placement"
    }
  ];
}

// Specifies an ad unit and (optionally) its descendants.
message AdUnitTargeting {
  // Whether this ad unit's children should be targeted/excluded as well.
  optional bool include_descendants = 1;

  // Optional. The resource name of this ad unit.
  optional string ad_unit = 3 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/AdUnit"
    }
  ];
}

// Represents a list of targeted request platforms.
message RequestPlatformTargeting {
  // Optional. The list of request platforms that should be targeted.
  repeated RequestPlatformEnum.RequestPlatform request_platforms = 1
      [(google.api.field_behavior) = OPTIONAL];
}

// Represents the top level targeting expression for custom key/values,
// audience segments, and/or CMS metadata.
message CustomTargeting {
  // Optional. These clauses are all ORed together.
  repeated CustomTargetingClause custom_targeting_clauses = 1
      [(google.api.field_behavior) = OPTIONAL];
}

// Represents a logical AND of individual custom targeting expressions.
message CustomTargetingClause {
  // Optional. Leaf targeting expressions for custom key/values.
  repeated CustomTargetingLiteral custom_targeting_literals = 1
      [(google.api.field_behavior) = OPTIONAL];
}

// Represents targeting for custom key/values. The values are ORed together.
message CustomTargetingLiteral {
  // Whether this expression is negatively targeted, meaning it matches
  // ad requests that exclude the below values.
  optional bool negative = 1;

  // Optional. The resource name of the targeted CustomKey.
  optional string custom_targeting_key = 4 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/CustomTargetingKey"
    }
  ];

  // Optional. The resource names of the targeted CustomValues.
  repeated string custom_targeting_values = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/CustomTargetingValue"
    }
  ];
}

// User Domain Targeting
message UserDomainTargeting {
  // Optional. A list of user domains that should be targeted/included.
  repeated string targeted_user_domains = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. A list of user domains that should be excluded.
  repeated string excluded_user_domains = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// Video Position Targeting
message VideoPositionTargeting {
  // Optional. A list of video position targeting criterion (applied with a
  // logical AND).
  repeated VideoPosition video_positions = 1
      [(google.api.field_behavior) = OPTIONAL];
}

// Video Position Targeting Criterion
message VideoPosition {
  // Optional. The index of the mid-roll to target. This field is ignored when
  // targeting any video position (e.g. position_type) other than MIDROLL.
  optional int64 midroll_index = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The index from the back of the pod of the mid-roll to target.
  // This field is ignored when targeting any video position (e.g.
  // position_type) other than MIDROLL or if targeting a specific midroll index
  // (e.g. midroll_index != 0).
  optional int64 reverse_midroll_index = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The video position within a pod to target. This field must be
  // unset in order to target a specific video position (e.g. position_type),
  // bumper type (e.g. bumper_type), or custom ad spot (e.g. custom_spot_id).
  optional int64 pod_position = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The position within a video to target. A video ad can target a
  // position (pre-roll, all mid-rolls, or post-roll) or a specific mid-roll
  // index.
  optional VideoPositionEnum.VideoPosition position_type = 5
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The video bumper type to target. This field must be unset in
  // order to target a specific video position (e.g. position_type), pod
  // position (e.g. pod_position), or custom ad spot (e.g. custom_spot_id).
  optional TargetedVideoBumperTypeEnum.TargetedVideoBumperType bumper_type = 6
      [(google.api.field_behavior) = OPTIONAL];
}

// Data Segment Targeting
message DataSegmentTargeting {
  // Output only. Whether any data segments are currently targeted.
  bool has_data_segment_targeting = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];
}
