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

/// Recon configs
public struct ReconConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Extra options that affect entity clustering behavior.
  public var options: ReconConfig.Options? = nil

  /// Model Configs
  public var modelConfig: ReconConfig.ModelConfig? = nil

  /// Choice of clustering algorithm. Default is ConnectedComponentsConfig.
  public var clusteringConfig: OneOf_ClusteringConfig? = nil

  /// Initialize a new instance of `ReconConfig`.
  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 = ReconConfig().with { $0.connectedComponentsConfig = ... }
  /// ```
  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 connectedComponentsConfig = "connectedComponentsConfig"
    case affinityClusteringConfig = "affinityClusteringConfig"
    case options = "options"
    case modelConfig = "modelConfig"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.options = try container.decodeIfPresent(ReconConfig.Options.self, forKey: .options)
    self.modelConfig = try container.decodeIfPresent(
      ReconConfig.ModelConfig.self, forKey: .modelConfig)

    var clusteringConfig: OneOf_ClusteringConfig? = nil
    let clusteringConfigCheckAndSet = {
      if clusteringConfig != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'clusteringConfig'"))
      }
      clusteringConfig = $0
    }
    if let connectedComponentsConfig = try container.decodeIfPresent(
      ConnectedComponentsConfig?.self, forKey: .connectedComponentsConfig)
    {
      try clusteringConfigCheckAndSet(.connectedComponentsConfig(connectedComponentsConfig))
    }
    if let affinityClusteringConfig = try container.decodeIfPresent(
      AffinityClusteringConfig?.self, forKey: .affinityClusteringConfig)
    {
      try clusteringConfigCheckAndSet(.affinityClusteringConfig(affinityClusteringConfig))
    }
    self.clusteringConfig = clusteringConfig
  }

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

    if let choice = self.clusteringConfig {
      switch choice {
      case .connectedComponentsConfig(let value):
        try container.encode(value, forKey: .connectedComponentsConfig)
      case .affinityClusteringConfig(let value):
        try container.encode(value, forKey: .affinityClusteringConfig)
      }
    }
  }

  /// Options for experimental changes on entity clustering behavior.
  public struct Options: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// If true, separate clusters by their geographic region (from geocoding).
    /// Uses the following entity features:
    ///
    /// - schema.org/addressLocality
    /// - schema.org/addressRegion
    /// - schema.org/addressCountry
    /// Warning: processing will no longer be regionalized!
    public var enableGeocodingSeparation: Swift.Bool = Swift.Bool()

    /// Initialize a new instance of `Options`.
    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 = Options().with { $0.enableGeocodingSeparation = ... }
    /// ```
    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.enterpriseknowledgegraph.v1.ReconConfig.Options"
    }
    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)
    }
  }

  /// Model Configs
  public struct ModelConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Model name. Refer to external documentation for valid names.
    /// If unspecified, it defaults to the one mentioned in the documentation.
    public var modelName: Swift.String = Swift.String()

    /// Model version tag. Refer to external documentation for valid tags.
    /// If unspecified, it defaults to the one mentioned in the documentation.
    public var versionTag: Swift.String = Swift.String()

    /// Initialize a new instance of `ModelConfig`.
    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 = ModelConfig().with { $0.modelName = ... }
    /// ```
    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.enterpriseknowledgegraph.v1.ReconConfig.ModelConfig"
    }
    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)
    }
  }

  /// Choice of clustering algorithm. Default is ConnectedComponentsConfig.
  public enum OneOf_ClusteringConfig: Codable, Equatable, Sendable {
    /// Configs for connected components.
    indirect case connectedComponentsConfig(ConnectedComponentsConfig?)
    /// Configs for affinity clustering.
    indirect case affinityClusteringConfig(AffinityClusteringConfig?)
  }

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