// Code generated by sidekick. DO NOT EDIT.
//
// 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
//
//     https://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.

import Foundation
import GoogleCloudWkt

/// A pair of time series filters that define a ratio computation. The output
/// time series is the pair-wise division of each aligned element from the
/// numerator and denominator time series.
public struct TimeSeriesFilterRatio: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The numerator of the ratio.
  public var numerator: TimeSeriesFilterRatio.RatioPart? = nil

  /// The denominator of the ratio.
  public var denominator: TimeSeriesFilterRatio.RatioPart? = nil

  /// Apply a second aggregation after the ratio is computed.
  public var secondaryAggregation: Aggregation? = nil

  /// Selects an optional filter that is applied to the time series after
  /// computing the ratio.
  public var outputFilter: OneOf_OutputFilter? = nil

  /// Initialize a new instance of `TimeSeriesFilterRatio`.
  public init() {}

  /// Use `config` to return a new instance of this object, with some fields updated.
  ///
  /// Commonly used to initialize the value, for example:
  ///
  /// ```
  /// let value = TimeSeriesFilterRatio().with { $0.numerator = ... }
  /// ```
  public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
    var copy = self
    try config(&copy)
    return copy
  }

  private enum CodingKeys: Swift.String, CodingKey {
    case numerator = "numerator"
    case denominator = "denominator"
    case secondaryAggregation = "secondaryAggregation"
    case pickTimeSeriesFilter = "pickTimeSeriesFilter"
    case statisticalTimeSeriesFilter = "statisticalTimeSeriesFilter"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.numerator = try container.decodeIfPresent(
      TimeSeriesFilterRatio.RatioPart.self, forKey: .numerator)
    self.denominator = try container.decodeIfPresent(
      TimeSeriesFilterRatio.RatioPart.self, forKey: .denominator)
    self.secondaryAggregation = try container.decodeIfPresent(
      Aggregation.self, forKey: .secondaryAggregation)

    var outputFilter: OneOf_OutputFilter? = nil
    let outputFilterCheckAndSet = {
      if outputFilter != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'outputFilter'"))
      }
      outputFilter = $0
    }
    if let pickTimeSeriesFilter = try container.decodeIfPresent(
      PickTimeSeriesFilter?.self, forKey: .pickTimeSeriesFilter)
    {
      try outputFilterCheckAndSet(.pickTimeSeriesFilter(pickTimeSeriesFilter))
    }
    if let statisticalTimeSeriesFilter = try container.decodeIfPresent(
      StatisticalTimeSeriesFilter?.self, forKey: .statisticalTimeSeriesFilter)
    {
      try outputFilterCheckAndSet(.statisticalTimeSeriesFilter(statisticalTimeSeriesFilter))
    }
    self.outputFilter = outputFilter
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.numerator, forKey: .numerator)
    try container.encode(self.denominator, forKey: .denominator)
    try container.encode(self.secondaryAggregation, forKey: .secondaryAggregation)

    if let choice = self.outputFilter {
      switch choice {
      case .pickTimeSeriesFilter(let value):
        try container.encode(value, forKey: .pickTimeSeriesFilter)
      case .statisticalTimeSeriesFilter(let value):
        try container.encode(value, forKey: .statisticalTimeSeriesFilter)
      }
    }
  }

  /// Describes a query to build the numerator or denominator of a
  /// TimeSeriesFilterRatio.
  public struct RatioPart: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The [monitoring
    /// filter](https://cloud.google.com/monitoring/api/v3/filters) that
    /// identifies the metric types, resources, and projects to query.
    public var filter: Swift.String = Swift.String()

    /// By default, the raw time series data is returned.
    /// Use this field to combine multiple time series for different views of the
    /// data.
    public var aggregation: Aggregation? = nil

    /// Initialize a new instance of `RatioPart`.
    public init() {}

    /// Use `config` to return a new instance of this object, with some fields updated.
    ///
    /// Commonly used to initialize the value, for example:
    ///
    /// ```
    /// let value = RatioPart().with { $0.filter = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.monitoring.dashboard.v1.TimeSeriesFilterRatio.RatioPart"
    }
    public init(fromAny any: GoogleCloudWkt.`Any`) throws {
      self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
    }
    public func _pack() throws -> GoogleCloudWkt.Struct {
      return try GoogleCloudWkt._slowAnySerialize(message: self)
    }
  }

  /// Selects an optional filter that is applied to the time series after
  /// computing the ratio.
  public enum OneOf_OutputFilter: Codable, Equatable, Sendable {
    /// Ranking based time series filter.
    indirect case pickTimeSeriesFilter(PickTimeSeriesFilter?)
    /// Statistics based time series filter.
    /// Note: This field is deprecated and completely ignored by the API.
    @available(*, deprecated)
    indirect case statisticalTimeSeriesFilter(StatisticalTimeSeriesFilter?)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.monitoring.dashboard.v1.TimeSeriesFilterRatio"
  }
  public init(fromAny any: GoogleCloudWkt.`Any`) throws {
    self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
  }
  public func _pack() throws -> GoogleCloudWkt.Struct {
    return try GoogleCloudWkt._slowAnySerialize(message: self)
  }
}
