// 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/ad_break_messages.proto";
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";

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 = "AdBreakServiceProto";
option java_package = "com.google.ads.admanager.v1";
option php_namespace = "Google\\Ads\\AdManager\\V1";
option ruby_package = "Google::Ads::AdManager::V1";

// Provides methods for handling `AdBreak` objects.
service AdBreakService {
  option (google.api.default_host) = "admanager.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/admanager";

  // API to retrieve an `AdBreak` object.
  //
  // Query an ad break by its resource name or custom asset key. Check the
  // resource's `breakState` field to determine its state.
  rpc GetAdBreak(GetAdBreakRequest) returns (AdBreak) {
    option (google.api.http) = {
      get: "/v1/{name=networks/*/liveStreamEventsByAssetKey/*/adBreaks/*}"
      additional_bindings {
        get: "/v1/{name=networks/*/liveStreamEventsByCustomAssetKey/*/adBreaks/*}"
      }
      additional_bindings {
        get: "/v1/{name=networks/*/liveStreamEvents/*/adBreaks/*}"
      }
    };
    option (google.api.method_signature) = "name";
  }

  // API to retrieve a list of `AdBreak` objects.
  //
  // By default, when no `orderBy` query parameter is specified, ad breaks are
  // ordered reverse chronologically. However, ad breaks with a 'breakState' of
  // 'SCHEDULED' or 'DECISIONED' are prioritized and appear first.
  rpc ListAdBreaks(ListAdBreaksRequest) returns (ListAdBreaksResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=networks/*/liveStreamEventsByAssetKey/*}/adBreaks"
      additional_bindings {
        get: "/v1/{parent=networks/*/liveStreamEventsByCustomAssetKey/*}/adBreaks"
      }
      additional_bindings {
        get: "/v1/{parent=networks/*/liveStreamEvents/*}/adBreaks"
      }
    };
    option (google.api.method_signature) = "parent";
  }

  // API to create an `AdBreak` object.
  //
  // Informs DAI of an upcoming ad break for a live stream event, with an
  // optional expected start time. DAI will begin decisioning ads for the break
  // shortly before the expected start time, if provided. Each live stream
  // event can only have one incomplete ad break at any given time. The next ad
  // break can be scheduled after the previous ad break has started serving,
  // indicated by its state being
  // [`COMPLETE`][google.ads.admanager.v1.AdBreakStateEnum.AdBreakState.COMPLETE],
  // or it has been deleted.
  //
  // This method cannot be used if the `LiveStreamEvent` has
  // [prefetching ad breaks
  // enabled](https://developers.google.com/ad-manager/api/reference/latest/LiveStreamEventService.LiveStreamEvent#prefetchenabled)
  // or the event is not active. If a `LiveStreamEvent` is deactivated after
  // creating an ad break and before the ad break is complete, the ad break
  // is discarded.
  //
  // An ad break's state is complete when the following occurs:
  //  - Full service DAI: after a matching ad break shows in the
  //  `LiveStreamEvent` manifest only when the ad break has started decisioning.
  //  - Pod Serving: after the ad break is requested using the ad break ID or
  //  break sequence.
  rpc CreateAdBreak(CreateAdBreakRequest) returns (AdBreak) {
    option (google.api.http) = {
      post: "/v1/{parent=networks/*/liveStreamEventsByAssetKey/*}/adBreaks"
      body: "ad_break"
      additional_bindings {
        post: "/v1/{parent=networks/*/liveStreamEventsByCustomAssetKey/*}/adBreaks"
        body: "ad_break"
      }
      additional_bindings {
        post: "/v1/{parent=networks/*/liveStreamEvents/*}/adBreaks"
        body: "ad_break"
      }
    };
    option (google.api.method_signature) = "parent,ad_break";
  }

  // API to update an `AdBreak` object.
  //
  // Modify an ad break when its state is
  // [`SCHEDULED`][google.ads.admanager.v1.AdBreakStateEnum.AdBreakState.SCHEDULED].
  rpc UpdateAdBreak(UpdateAdBreakRequest) returns (AdBreak) {
    option (google.api.http) = {
      patch: "/v1/{ad_break.name=networks/*/liveStreamEventsByAssetKey/*/adBreaks/*}"
      body: "ad_break"
    };
    option (google.api.method_signature) = "ad_break,update_mask";
  }

  // API to delete an `AdBreak` object.
  //
  // Deletes and cancels an incomplete ad break, mitigating the need to wait
  // for the current break to serve before recreating an ad break. You can
  // delete an ad break that has not started serving or seen in manifests,
  // indicated by its state being
  // [`SCHEDULED`][google.ads.admanager.v1.AdBreakStateEnum.AdBreakState.SCHEDULED]
  // or
  // [`DECISIONED`][google.ads.admanager.v1.AdBreakStateEnum.AdBreakState.DECISIONED].
  rpc DeleteAdBreak(DeleteAdBreakRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1/{name=networks/*/liveStreamEventsByAssetKey/*/adBreaks/*}"
    };
    option (google.api.method_signature) = "name";
  }
}

// Request object for `GetAdBreak` method.
message GetAdBreakRequest {
  // Required. The resource name of the AdBreak using the asset key or custom
  // asset key.
  //
  // Format:
  // `networks/{network_code}/liveStreamEventsByAssetKey/{asset_key}/adBreaks/{ad_break_id}`
  // `networks/{network_code}/liveStreamEventsByCustomAssetKey/{custom_asset_key}/adBreaks/{ad_break_id}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/AdBreak"
    }
  ];
}

// Request object for `ListAdBreaks` method.
message ListAdBreaksRequest {
  // Required. The parent, which owns this collection of AdBreaks.
  //
  // Formats:
  // `networks/{network_code}/liveStreamEventsByAssetKey/{asset_key}`
  // `networks/{network_code}/liveStreamEventsByCustomAssetKey/{custom_asset_key}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/LiveStreamEvent"
    }
  ];

  // Optional. The maximum number of `AdBreaks` to return. The service might
  // return fewer than this value. If unspecified, at most 10 ad breaks are
  // returned. The maximum value is `100`. Values above `100` are coerced to
  // `100`.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

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

  // Optional. Expression to filter the response.
  // See syntax details at
  // https://developers.google.com/ad-manager/api/beta/filters
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Expression to specify sorting order.
  // See syntax details at
  // https://developers.google.com/ad-manager/api/beta/filters#order
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Number of individual resources to skip while paginating.
  int32 skip = 6 [(google.api.field_behavior) = OPTIONAL];
}

// Response object for `ListAdBreaksRequest` containing matching `AdBreak`
// objects.
message ListAdBreaksResponse {
  // The `AdBreak` objects from the specified network.
  repeated AdBreak ad_breaks = 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. This field expires
  // after five minutes.
  string next_page_token = 2;

  // Total number of `AdBreak` objects.
  // If a filter was included in the request, this reflects the total number
  // after the filtering is applied.
  //
  // `total_size` won't be calculated in the response unless it has been
  // included in a response field mask. The response field mask can be provided
  // to the method by using the URL parameter `$fields` or `fields`, or by using
  // the HTTP/gRPC header `X-Goog-FieldMask`.
  //
  // For more information, see
  // https://developers.google.com/ad-manager/api/beta/field-masks
  int32 total_size = 3;
}

// Request object for `CreateAdBreak` method.
message CreateAdBreakRequest {
  // Required. The parent resource where this `AdBreak` will be created
  // identified by an asset key or custom asset key.
  //
  // Formats:
  // `networks/{network_code}/liveStreamEventsByAssetKey/{asset_key}`
  // `networks/{network_code}/liveStreamEventsByCustomAssetKey/{custom_asset_key}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/LiveStreamEvent"
    }
  ];

  // Required. The `AdBreak` to create.
  AdBreak ad_break = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request object for `UpdateAdBreak` method.
message UpdateAdBreakRequest {
  // Required. The `AdBreak` to update.
  //
  // The `AdBreak`'s `name` is used to identify the `AdBreak` to update.
  AdBreak ad_break = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The list of fields to update.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request object for `DeleteAdBreak` method.
message DeleteAdBreakRequest {
  // Required. The name of the ad break to delete.
  //
  // Format:
  // `networks/{network_code}/liveStreamEventsByAssetKey/{asset_key}/adBreaks/{ad_break}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "admanager.googleapis.com/AdBreak"
    }
  ];
}
