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

/// A configuration for running an [Apache Spark](https://spark.apache.org/)
/// batch workload.
public struct SparkBatch: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. The arguments to pass to the driver. Do not include arguments
  /// that can be set as batch properties, such as `--conf`, since a collision
  /// can occur that causes an incorrect batch submission.
  public var args: [Swift.String] = []

  /// Optional. HCFS URIs of jar files to add to the classpath of the
  /// Spark driver and tasks.
  public var jarFileUris: [Swift.String] = []

  /// Optional. HCFS URIs of files to be placed in the working directory of
  /// each executor.
  public var fileUris: [Swift.String] = []

  /// Optional. HCFS URIs of archives to be extracted into the working directory
  /// of each executor. Supported file types:
  /// `.jar`, `.tar`, `.tar.gz`, `.tgz`, and `.zip`.
  public var archiveUris: [Swift.String] = []

  /// The specification of the main method to call to drive the Spark
  /// workload. Specify either the jar file that contains the main class or the
  /// main class name. To pass both a main jar and a main class in that jar, add
  /// the jar to `jar_file_uris`, and then specify the main class
  /// name in `main_class`.
  public var driver: OneOf_Driver? = nil

  /// Initialize a new instance of `SparkBatch`.
  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 = SparkBatch().with { $0.mainJarFileUri = ... }
  /// ```
  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 mainJarFileUri = "mainJarFileUri"
    case mainClass = "mainClass"
    case args = "args"
    case jarFileUris = "jarFileUris"
    case fileUris = "fileUris"
    case archiveUris = "archiveUris"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.args = try container.decode([Swift.String].self, forKey: .args)
    self.jarFileUris = try container.decode([Swift.String].self, forKey: .jarFileUris)
    self.fileUris = try container.decode([Swift.String].self, forKey: .fileUris)
    self.archiveUris = try container.decode([Swift.String].self, forKey: .archiveUris)

    var driver: OneOf_Driver? = nil
    let driverCheckAndSet = {
      if driver != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'driver'"))
      }
      driver = $0
    }
    if let mainJarFileUri = try container.decodeIfPresent(
      Swift.String.self, forKey: .mainJarFileUri)
    {
      try driverCheckAndSet(.mainJarFileUri(mainJarFileUri))
    }
    if let mainClass = try container.decodeIfPresent(Swift.String.self, forKey: .mainClass) {
      try driverCheckAndSet(.mainClass(mainClass))
    }
    self.driver = driver
  }

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

    if let choice = self.driver {
      switch choice {
      case .mainJarFileUri(let value):
        try container.encode(value, forKey: .mainJarFileUri)
      case .mainClass(let value):
        try container.encode(value, forKey: .mainClass)
      }
    }
  }

  /// The specification of the main method to call to drive the Spark
  /// workload. Specify either the jar file that contains the main class or the
  /// main class name. To pass both a main jar and a main class in that jar, add
  /// the jar to `jar_file_uris`, and then specify the main class
  /// name in `main_class`.
  public enum OneOf_Driver: Codable, Equatable, Sendable {
    /// Optional. The HCFS URI of the jar file that contains the main class.
    case mainJarFileUri(Swift.String)
    /// Optional. The name of the driver main class. The jar file that contains
    /// the class must be in the classpath or specified in `jar_file_uris`.
    case mainClass(Swift.String)
  }

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