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

  /// Specification for an LLM based metric.
  public struct LLMBasedMetricSpec: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. Template for the prompt sent to the judge model.
    public var metricPromptTemplate: Swift.String? = nil

    /// Optional. System instructions for the judge model.
    public var systemInstruction: Swift.String? = nil

    /// Optional. Optional configuration for the judge LLM (Autorater).
    public var judgeAutoraterConfig: AutoraterConfig? = nil

    /// Optional. Optional additional configuration for the metric.
    public var additionalConfig: GoogleCloudWkt.Struct? = nil

    /// Source of the rubrics to be used for evaluation.
    public var rubricsSource: OneOf_RubricsSource? = nil

    /// Initialize a new instance of `LLMBasedMetricSpec`.
    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 = LLMBasedMetricSpec().with { $0.rubricGroupKey = ... }
    /// ```
    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 rubricGroupKey = "rubricGroupKey"
      case predefinedRubricGenerationSpec = "predefinedRubricGenerationSpec"
      case metricPromptTemplate = "metricPromptTemplate"
      case systemInstruction = "systemInstruction"
      case judgeAutoraterConfig = "judgeAutoraterConfig"
      case additionalConfig = "additionalConfig"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.metricPromptTemplate = try container.decodeIfPresent(
        Swift.String.self, forKey: .metricPromptTemplate)
      self.systemInstruction = try container.decodeIfPresent(
        Swift.String.self, forKey: .systemInstruction)
      self.judgeAutoraterConfig = try container.decodeIfPresent(
        AutoraterConfig.self, forKey: .judgeAutoraterConfig)
      self.additionalConfig = try container.decodeIfPresent(
        GoogleCloudWkt.Struct.self, forKey: .additionalConfig)

      var rubricsSource: OneOf_RubricsSource? = nil
      let rubricsSourceCheckAndSet = {
        if rubricsSource != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'rubricsSource'"))
        }
        rubricsSource = $0
      }
      if let rubricGroupKey = try container.decodeIfPresent(
        Swift.String.self, forKey: .rubricGroupKey)
      {
        try rubricsSourceCheckAndSet(.rubricGroupKey(rubricGroupKey))
      }
      if let predefinedRubricGenerationSpec = try container.decodeIfPresent(
        PredefinedMetricSpec?.self, forKey: .predefinedRubricGenerationSpec)
      {
        try rubricsSourceCheckAndSet(
          .predefinedRubricGenerationSpec(predefinedRubricGenerationSpec))
      }
      self.rubricsSource = rubricsSource
    }

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

      if let choice = self.rubricsSource {
        switch choice {
        case .rubricGroupKey(let value):
          try container.encode(value, forKey: .rubricGroupKey)
        case .predefinedRubricGenerationSpec(let value):
          try container.encode(value, forKey: .predefinedRubricGenerationSpec)
        }
      }
    }

    /// Source of the rubrics to be used for evaluation.
    public enum OneOf_RubricsSource: Codable, Equatable, Sendable {
      /// Use a pre-defined group of rubrics associated with the input.
      /// Refers to a key in the rubric_groups map of EvaluationInstance.
      case rubricGroupKey(Swift.String)
      /// Dynamically generate rubrics using a predefined spec.
      indirect case predefinedRubricGenerationSpec(PredefinedMetricSpec?)
    }

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