// 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 DeploymentResourcePoolService || EndpointService
  import Foundation
  import GoogleCloudWkt

  /// Configuration for Speculative Decoding.
  public struct SpeculativeDecodingSpec: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The number of speculative tokens to generate at each step.
    public var speculativeTokenCount: Swift.Int32 = Swift.Int32()

    /// The type of speculation method to use.
    public var speculation: OneOf_Speculation? = nil

    /// Initialize a new instance of `SpeculativeDecodingSpec`.
    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 = SpeculativeDecodingSpec().with { $0.draftModelSpeculation = ... }
    /// ```
    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 draftModelSpeculation = "draftModelSpeculation"
      case ngramSpeculation = "ngramSpeculation"
      case speculativeTokenCount = "speculativeTokenCount"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.speculativeTokenCount = try container.decode(
        Swift.Int32.self, forKey: .speculativeTokenCount)

      var speculation: OneOf_Speculation? = nil
      let speculationCheckAndSet = {
        if speculation != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'speculation'"))
        }
        speculation = $0
      }
      if let draftModelSpeculation = try container.decodeIfPresent(
        SpeculativeDecodingSpec.DraftModelSpeculation?.self, forKey: .draftModelSpeculation)
      {
        try speculationCheckAndSet(.draftModelSpeculation(draftModelSpeculation))
      }
      if let ngramSpeculation = try container.decodeIfPresent(
        SpeculativeDecodingSpec.NgramSpeculation?.self, forKey: .ngramSpeculation)
      {
        try speculationCheckAndSet(.ngramSpeculation(ngramSpeculation))
      }
      self.speculation = speculation
    }

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

      if let choice = self.speculation {
        switch choice {
        case .draftModelSpeculation(let value):
          try container.encode(value, forKey: .draftModelSpeculation)
        case .ngramSpeculation(let value):
          try container.encode(value, forKey: .ngramSpeculation)
        }
      }
    }

    /// Draft model speculation works by using the smaller model to generate
    /// candidate tokens for speculative decoding.
    public struct DraftModelSpeculation: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. The resource name of the draft model.
      public var draftModel: Swift.String = Swift.String()

      /// Initialize a new instance of `DraftModelSpeculation`.
      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 = DraftModelSpeculation().with { $0.draftModel = ... }
      /// ```
      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.cloud.aiplatform.v1.SpeculativeDecodingSpec.DraftModelSpeculation"
      }
      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)
      }
    }

    /// N-Gram speculation works by trying to find matching tokens in the
    /// previous prompt sequence and use those as speculation for generating
    /// new tokens.
    public struct NgramSpeculation: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// The number of last N input tokens used as ngram to search/match
      /// against the previous prompt sequence.
      /// This is equal to the N in N-Gram.
      /// The default value is 3 if not specified.
      public var ngramSize: Swift.Int32 = Swift.Int32()

      /// Initialize a new instance of `NgramSpeculation`.
      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 = NgramSpeculation().with { $0.ngramSize = ... }
      /// ```
      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.cloud.aiplatform.v1.SpeculativeDecodingSpec.NgramSpeculation"
      }
      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)
      }
    }

    /// The type of speculation method to use.
    public enum OneOf_Speculation: Codable, Equatable, Sendable {
      /// draft model speculation.
      indirect case draftModelSpeculation(SpeculativeDecodingSpec.DraftModelSpeculation?)
      /// N-Gram speculation.
      indirect case ngramSpeculation(SpeculativeDecodingSpec.NgramSpeculation?)
    }

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