// 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

/// TimeSeriesQuery collects the set of supported methods for querying time
/// series data from the Stackdriver metrics API.
public struct TimeSeriesQuery: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The unit of data contained in fetched time series. If non-empty, this
  /// unit will override any unit that accompanies fetched data. The format is
  /// the same as the
  /// [`unit`](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors)
  /// field in `MetricDescriptor`.
  public var unitOverride: Swift.String = Swift.String()

  /// Optional. If set, Cloud Monitoring will treat the full query duration as
  /// the alignment period so that there will be only 1 output value.
  ///
  /// *Note: This could override the configured alignment period except for
  /// the cases where a series of data points are expected, like
  ///   - XyChart
  ///   - Scorecard's spark chart
  public var outputFullDuration: Swift.Bool = Swift.Bool()

  /// Parameters needed to obtain data for the chart.
  public var source: OneOf_Source? = nil

  /// Initialize a new instance of `TimeSeriesQuery`.
  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 = TimeSeriesQuery().with { $0.timeSeriesFilter = ... }
  /// ```
  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 timeSeriesFilter = "timeSeriesFilter"
    case timeSeriesFilterRatio = "timeSeriesFilterRatio"
    case timeSeriesQueryLanguage = "timeSeriesQueryLanguage"
    case prometheusQuery = "prometheusQuery"
    case unitOverride = "unitOverride"
    case outputFullDuration = "outputFullDuration"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.unitOverride = try container.decode(Swift.String.self, forKey: .unitOverride)
    self.outputFullDuration = try container.decode(Swift.Bool.self, forKey: .outputFullDuration)

    var source: OneOf_Source? = nil
    let sourceCheckAndSet = {
      if source != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'source'"))
      }
      source = $0
    }
    if let timeSeriesFilter = try container.decodeIfPresent(
      TimeSeriesFilter?.self, forKey: .timeSeriesFilter)
    {
      try sourceCheckAndSet(.timeSeriesFilter(timeSeriesFilter))
    }
    if let timeSeriesFilterRatio = try container.decodeIfPresent(
      TimeSeriesFilterRatio?.self, forKey: .timeSeriesFilterRatio)
    {
      try sourceCheckAndSet(.timeSeriesFilterRatio(timeSeriesFilterRatio))
    }
    if let timeSeriesQueryLanguage = try container.decodeIfPresent(
      Swift.String.self, forKey: .timeSeriesQueryLanguage)
    {
      try sourceCheckAndSet(.timeSeriesQueryLanguage(timeSeriesQueryLanguage))
    }
    if let prometheusQuery = try container.decodeIfPresent(
      Swift.String.self, forKey: .prometheusQuery)
    {
      try sourceCheckAndSet(.prometheusQuery(prometheusQuery))
    }
    self.source = source
  }

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

    if let choice = self.source {
      switch choice {
      case .timeSeriesFilter(let value):
        try container.encode(value, forKey: .timeSeriesFilter)
      case .timeSeriesFilterRatio(let value):
        try container.encode(value, forKey: .timeSeriesFilterRatio)
      case .timeSeriesQueryLanguage(let value):
        try container.encode(value, forKey: .timeSeriesQueryLanguage)
      case .prometheusQuery(let value):
        try container.encode(value, forKey: .prometheusQuery)
      }
    }
  }

  /// Parameters needed to obtain data for the chart.
  public enum OneOf_Source: Codable, Equatable, Sendable {
    /// Filter parameters to fetch time series.
    indirect case timeSeriesFilter(TimeSeriesFilter?)
    /// Parameters to fetch a ratio between two time series filters.
    indirect case timeSeriesFilterRatio(TimeSeriesFilterRatio?)
    /// A query used to fetch time series with MQL.
    case timeSeriesQueryLanguage(Swift.String)
    /// A query used to fetch time series with PromQL.
    case prometheusQuery(Swift.String)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.monitoring.dashboard.v1.TimeSeriesQuery"
  }
  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)
  }
}
