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

  /// TunedModel Reference for legacy model migration.
  public struct TunedModelRef: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The Tuned Model Reference for the model.
    public var tunedModelRef: OneOf_TunedModelRef? = nil

    /// Initialize a new instance of `TunedModelRef`.
    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 = TunedModelRef().with { $0.tunedModel = ... }
    /// ```
    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 tunedModel = "tunedModel"
      case tuningJob = "tuningJob"
      case pipelineJob = "pipelineJob"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)

      var tunedModelRef: OneOf_TunedModelRef? = nil
      let tunedModelRefCheckAndSet = {
        if tunedModelRef != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'tunedModelRef'"))
        }
        tunedModelRef = $0
      }
      if let tunedModel = try container.decodeIfPresent(Swift.String.self, forKey: .tunedModel) {
        try tunedModelRefCheckAndSet(.tunedModel(tunedModel))
      }
      if let tuningJob = try container.decodeIfPresent(Swift.String.self, forKey: .tuningJob) {
        try tunedModelRefCheckAndSet(.tuningJob(tuningJob))
      }
      if let pipelineJob = try container.decodeIfPresent(Swift.String.self, forKey: .pipelineJob) {
        try tunedModelRefCheckAndSet(.pipelineJob(pipelineJob))
      }
      self.tunedModelRef = tunedModelRef
    }

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

      if let choice = self.tunedModelRef {
        switch choice {
        case .tunedModel(let value):
          try container.encode(value, forKey: .tunedModel)
        case .tuningJob(let value):
          try container.encode(value, forKey: .tuningJob)
        case .pipelineJob(let value):
          try container.encode(value, forKey: .pipelineJob)
        }
      }
    }

    /// The Tuned Model Reference for the model.
    public enum OneOf_TunedModelRef: Codable, Equatable, Sendable {
      /// Support migration from model registry.
      case tunedModel(Swift.String)
      /// Support migration from tuning job list page, from gemini-1.0-pro-002
      /// to 1.5 and above.
      case tuningJob(Swift.String)
      /// Support migration from tuning job list page, from bison model to gemini
      /// model.
      case pipelineJob(Swift.String)
    }

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