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

/// Represents a hint to the search index engine.
public struct SearchHint: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The type of index to use.
  public var indexType: OneOf_IndexType? = nil

  /// Initialize a new instance of `SearchHint`.
  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 = SearchHint().with { $0.knnHint = ... }
  /// ```
  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 knnHint = "knnHint"
    case indexHint = "indexHint"
  }

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

    var indexType: OneOf_IndexType? = nil
    let indexTypeCheckAndSet = {
      if indexType != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'indexType'"))
      }
      indexType = $0
    }
    if let knnHint = try container.decodeIfPresent(SearchHint.KnnHint?.self, forKey: .knnHint) {
      try indexTypeCheckAndSet(.knnHint(knnHint))
    }
    if let indexHint = try container.decodeIfPresent(SearchHint.IndexHint?.self, forKey: .indexHint)
    {
      try indexTypeCheckAndSet(.indexHint(indexHint))
    }
    self.indexType = indexType
  }

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

    if let choice = self.indexType {
      switch choice {
      case .knnHint(let value):
        try container.encode(value, forKey: .knnHint)
      case .indexHint(let value):
        try container.encode(value, forKey: .indexHint)
      }
    }
  }

  /// Message to specify the index to use for the search.
  public struct IndexHint: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The resource name of the index to use for the search.
    /// The index must be in the same project, location, and collection.
    /// Format:
    /// `projects/{project}/locations/{location}/collections/{collection}/indexes/{index}`
    public var name: Swift.String = Swift.String()

    /// Initialize a new instance of `IndexHint`.
    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 = IndexHint().with { $0.name = ... }
    /// ```
    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.vectorsearch.v1.SearchHint.IndexHint"
    }
    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)
    }
  }

  /// KnnHint will be used if search should be explicitly done on system's
  /// default K-Nearest Neighbor (KNN) index engine.
  public struct KnnHint: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Initialize a new instance of `KnnHint`.
    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 = KnnHint().with { $0.<placeholder> = ... }
    /// ```
    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.vectorsearch.v1.SearchHint.KnnHint"
    }
    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 index to use.
  public enum OneOf_IndexType: Codable, Equatable, Sendable {
    /// Optional. If set, the search will use the system's default
    /// K-Nearest Neighbor (KNN) index engine.
    indirect case knnHint(SearchHint.KnnHint?)
    /// Optional. Specifies that the search should use a particular index.
    indirect case indexHint(SearchHint.IndexHint?)
  }

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