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

/// The configuration for running the Dataproc cluster on Kubernetes.
public struct KubernetesClusterConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. A namespace within the Kubernetes cluster to deploy into. If this
  /// namespace does not exist, it is created. If it exists, Dataproc verifies
  /// that another Dataproc VirtualCluster is not installed into it. If not
  /// specified, the name of the Dataproc Cluster is used.
  public var kubernetesNamespace: Swift.String = Swift.String()

  /// Optional. The software configuration for this Dataproc cluster running on
  /// Kubernetes.
  public var kubernetesSoftwareConfig: KubernetesSoftwareConfig? = nil

  public var config: OneOf_Config? = nil

  /// Initialize a new instance of `KubernetesClusterConfig`.
  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 = KubernetesClusterConfig().with { $0.kubernetesNamespace = ... }
  /// ```
  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 kubernetesNamespace = "kubernetesNamespace"
    case gkeClusterConfig = "gkeClusterConfig"
    case kubernetesSoftwareConfig = "kubernetesSoftwareConfig"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.kubernetesNamespace = try container.decode(Swift.String.self, forKey: .kubernetesNamespace)
    self.kubernetesSoftwareConfig = try container.decodeIfPresent(
      KubernetesSoftwareConfig.self, forKey: .kubernetesSoftwareConfig)

    var config: OneOf_Config? = nil
    let configCheckAndSet = {
      if config != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'config'"))
      }
      config = $0
    }
    if let gkeClusterConfig = try container.decodeIfPresent(
      GkeClusterConfig?.self, forKey: .gkeClusterConfig)
    {
      try configCheckAndSet(.gkeClusterConfig(gkeClusterConfig))
    }
    self.config = config
  }

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

    if let choice = self.config {
      switch choice {
      case .gkeClusterConfig(let value):
        try container.encode(value, forKey: .gkeClusterConfig)
      }
    }
  }

  public enum OneOf_Config: Codable, Equatable, Sendable {
    /// Required. The configuration for running the Dataproc cluster on GKE.
    indirect case gkeClusterConfig(GkeClusterConfig?)
  }

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