// 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/report_definition.proto";
import "google/ads/admanager/v1/report_value.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.proto";
import "google/type/date.proto";
import "google/type/dayofweek.proto";
import "google/type/timeofday.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 = "ReportMessagesProto";
option java_package = "com.google.ads.admanager.v1";
option php_namespace = "Google\\Ads\\AdManager\\V1";
option ruby_package = "Google::Ads::AdManager::V1";

// The `Report` resource.
message Report {
  option (google.api.resource) = {
    type: "admanager.googleapis.com/Report"
    pattern: "networks/{network_code}/reports/{report}"
    plural: "reports"
    singular: "report"
  };

  // The visibility of a report.
  enum Visibility {
    option allow_alias = true;

    // Default value. Reports with hidden visibility won't appear in the Ad
    // Manager UI.
    HIDDEN = 0;

    // Reports with draft visibility will appear in the Ad Manager UI only if
    // the user has configured the UI to show them.
    DRAFT = 1;

    // Reports with saved visibility will appear in the Ad Manager UI by
    // default. Alias for VISIBLE and will be replaced in the future.
    SAVED = 2 [deprecated = true];

    // Reports with this visibility will appear in the Ad Manager UI.
    VISIBLE = 2;
  }

  // Identifier. The resource name of the report.
  // Report resource name have the form:
  // `networks/{network_code}/reports/{report_id}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. Report ID.
  int64 report_id = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The visibility of a report.
  Visibility visibility = 2 [(google.api.field_behavior) = OPTIONAL];

  // Required. The report definition of the report.
  ReportDefinition report_definition = 4
      [(google.api.field_behavior) = REQUIRED];

  // Optional. Display name for the report.
  string display_name = 5 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The instant this report was last modified.
  google.protobuf.Timestamp update_time = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The instant this report was created.
  google.protobuf.Timestamp create_time = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The locale of this report. Locale is set from the user's
  // locale at the time of the request. Locale can't be modified.
  string locale = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The schedule options of this report.
  ScheduleOptions schedule_options = 9 [(google.api.field_behavior) = OPTIONAL];
}

// A table containing report data including dimension and metric values.
message ReportDataTable {
  // A row of report data.
  message Row {
    // The order of the dimension values is the same as the order of the
    // dimensions specified in the request.
    repeated ReportValue dimension_values = 1;

    //
    // The length of the metric_value_groups
    // field will be equal to the length of the date_ranges field in the
    // fetch response. The metric_value_groups field is
    // ordered such that each index corresponds to the date_range at the same
    // index. For example, given date_ranges [x, y], metric_value_groups will
    // have a length of two. The first entry in metric_value_groups represents
    // the metrics for date x and the second entry in metric_value_groups
    // represents the metrics for date y.
    repeated MetricValueGroup metric_value_groups = 2;
  }

  // Contains all metric values requested for a single date range and set of
  // column dimension values (returned in the columns field of the response).
  // The order of the metrics in each field corresponds to the order of the
  // metrics specified in the request.
  message MetricValueGroup {
    // Data for the PRIMARY MetricValueType.
    repeated ReportValue primary_values = 1;

    // Data for the PRIMARY_PERCENT_OF_TOTAL MetricValueType.
    repeated ReportValue primary_percent_of_total_values = 2;

    // Data for the COMPARISON MetricValueType.
    repeated ReportValue comparison_values = 3;

    // Data for the COMPARISON_PERCENT_OF_TOTAL MetricValueType.
    repeated ReportValue comparison_percent_of_total_values = 4;

    // Data for the ABSOLUTE_CHANGE MetricValueType.
    repeated ReportValue absolute_change_values = 5;

    // Data for the RELATIVE_CHANGE MetricValueType.
    repeated ReportValue relative_change_values = 6;

    // If true, the flag's conditions are met. If false, the flag's
    // conditions are not met. flag_values has the same length as
    // flags and index i of flag_values represents the flag at index i
    // of flags.
    repeated bool flag_values = 7;
  }
}

// The options for a scheduled report.
message ScheduleOptions {
  // The schedule for the report
  message Schedule {
    // Days of week to schedule report run.
    message WeeklySchedule {
      // Specifies days of the week on which to run report.
      repeated google.type.DayOfWeek weekly_scheduled_days = 1;
    }

    // Days of Month to schedule report run.
    message MonthlySchedule {
      // Specifies days of the month to run report. Range is from 1-31.
      // Will ignore days that are not valid for the given month.
      repeated int32 monthly_scheduled_days = 1;
    }

    // Frequency to run report.
    enum Frequency {
      // No Frequency specified.
      FREQUENCY_UNSPECIFIED = 0;

      // Schedule report to run every hour.
      HOURLY = 1;

      // Schedule report to run twice a day (every 12 hours).
      TWO_TIMES_DAILY = 2;

      // Schedule report to run three times a day (every 8 hours).
      THREE_TIMES_DAILY = 3;

      // Schedule report to run four times a day (every 6 hours).
      FOUR_TIMES_DAILY = 4;

      // Schedule report to run on a daily basis.
      DAILY = 5;

      // Schedule report to run on a weekly basis.
      WEEKLY = 6;

      // Schedule report to run on a monthly basis.
      MONTHLY = 7;
    }

    // The scheduled values based on the frequency selected.
    // WEEKLY - uses WeeklySchedule
    // MONTHLY - uses MonthlySchedule
    oneof frequency_schedule {
      // Days of week to schedule report run.
      WeeklySchedule weekly_schedule = 6;

      // Days of month to schedule report run.
      MonthlySchedule monthly_schedule = 7;
    }

    // Date for the first run of the report.
    google.type.Date start_date = 1;

    // Date for the final run of the report.
    google.type.Date end_date = 2;

    // Frequency to run report.
    Frequency frequency = 3;

    // Indicates start time for schedule to run
    // Will use the time_zone from `ReportDefinition`. Defaults
    // to the publisher's time zone if not specified.
    //
    // For HOURLY, TWO_TIMES_DAILY, THREE_TIMES_DAILY, or FOUR_TIMES_DAILY, this
    // will be the time of day that the first report will run on the first day.
    // For example, if the start time is 2:00 PM, and the frequency is
    // THREE_TIMES_DAILY, the first day will have reports scheduled at 2:00 PM,
    // 10:00 PM. Each subsequent day will have reports scheduled at 6:00 AM,
    // 2:00 PM, 10:00 PM.
    google.type.TimeOfDay start_time = 4;
  }

  // Condition for when to email the scheduled report.
  enum DeliveryCondition {
    // Never deliver report.
    NEVER = 0;

    // Always deliver report.
    ALWAYS = 1;

    // Deliver report when flag's conditions are met.
    WHEN_FLAG_CONDITIONS_MET = 2;
  }

  // Information pertaining to schedule itself.
  Schedule schedule = 1;

  // Option for when to deliver the scheduled report.
  DeliveryCondition delivery_condition = 2;

  // Optional. The flags evaluated when ReportDeliveryOption.WHEN_FLAG_PRESENT
  // is specified.
  repeated ReportDefinition.Flag flags = 3
      [(google.api.field_behavior) = OPTIONAL];
}
