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

#if GenAiTuningService
  import Foundation
  import GoogleCloudWkt

  /// The aggregation result for a single metric.
  public struct AggregationResult: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Aggregation metric.
    public var aggregationMetric: Metric.AggregationMetric = Metric.AggregationMetric()

    /// The aggregation result.
    public var aggregationResult: OneOf_AggregationResult? = nil

    /// Initialize a new instance of `AggregationResult`.
    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 = AggregationResult().with { $0.pointwiseMetricResult = ... }
    /// ```
    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 pointwiseMetricResult = "pointwiseMetricResult"
      case pairwiseMetricResult = "pairwiseMetricResult"
      case exactMatchMetricValue = "exactMatchMetricValue"
      case bleuMetricValue = "bleuMetricValue"
      case rougeMetricValue = "rougeMetricValue"
      case aggregationMetric = "aggregationMetric"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.aggregationMetric = try container.decode(
        Metric.AggregationMetric.self, forKey: .aggregationMetric)

      var aggregationResult: OneOf_AggregationResult? = nil
      let aggregationResultCheckAndSet = {
        if aggregationResult != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'aggregationResult'"))
        }
        aggregationResult = $0
      }
      if let pointwiseMetricResult = try container.decodeIfPresent(
        PointwiseMetricResult?.self, forKey: .pointwiseMetricResult)
      {
        try aggregationResultCheckAndSet(.pointwiseMetricResult(pointwiseMetricResult))
      }
      if let pairwiseMetricResult = try container.decodeIfPresent(
        PairwiseMetricResult?.self, forKey: .pairwiseMetricResult)
      {
        try aggregationResultCheckAndSet(.pairwiseMetricResult(pairwiseMetricResult))
      }
      if let exactMatchMetricValue = try container.decodeIfPresent(
        ExactMatchMetricValue?.self, forKey: .exactMatchMetricValue)
      {
        try aggregationResultCheckAndSet(.exactMatchMetricValue(exactMatchMetricValue))
      }
      if let bleuMetricValue = try container.decodeIfPresent(
        BleuMetricValue?.self, forKey: .bleuMetricValue)
      {
        try aggregationResultCheckAndSet(.bleuMetricValue(bleuMetricValue))
      }
      if let rougeMetricValue = try container.decodeIfPresent(
        RougeMetricValue?.self, forKey: .rougeMetricValue)
      {
        try aggregationResultCheckAndSet(.rougeMetricValue(rougeMetricValue))
      }
      self.aggregationResult = aggregationResult
    }

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

      if let choice = self.aggregationResult {
        switch choice {
        case .pointwiseMetricResult(let value):
          try container.encode(value, forKey: .pointwiseMetricResult)
        case .pairwiseMetricResult(let value):
          try container.encode(value, forKey: .pairwiseMetricResult)
        case .exactMatchMetricValue(let value):
          try container.encode(value, forKey: .exactMatchMetricValue)
        case .bleuMetricValue(let value):
          try container.encode(value, forKey: .bleuMetricValue)
        case .rougeMetricValue(let value):
          try container.encode(value, forKey: .rougeMetricValue)
        }
      }
    }

    /// The aggregation result.
    public enum OneOf_AggregationResult: Codable, Equatable, Sendable {
      /// Result for pointwise metric.
      indirect case pointwiseMetricResult(PointwiseMetricResult?)
      /// Result for pairwise metric.
      indirect case pairwiseMetricResult(PairwiseMetricResult?)
      /// Results for exact match metric.
      indirect case exactMatchMetricValue(ExactMatchMetricValue?)
      /// Results for bleu metric.
      indirect case bleuMetricValue(BleuMetricValue?)
      /// Results for rouge metric.
      indirect case rougeMetricValue(RougeMetricValue?)
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.aiplatform.v1.AggregationResult"
    }
    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)
    }
  }
#endif
