// 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 Dataproc job for running [Apache Spark](https://spark.apache.org/)
/// applications on YARN.
public struct SparkJob: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. The arguments to pass to the driver. Do not include arguments,
  /// such as `--conf`, that can be set as job properties, since a collision may
  /// occur that causes an incorrect job submission.
  public var args: [Swift.String] = []

  /// Optional. HCFS URIs of jar files to add to the CLASSPATHs 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. Useful for naively parallel tasks.
  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] = []

  /// Optional. A mapping of property names to values, used to configure Spark.
  /// Properties that conflict with values set by the Dataproc API might be
  /// overwritten. Can include properties set in
  /// /etc/spark/conf/spark-defaults.conf and classes in user code.
  public var properties: [Swift.String: Swift.String] = [:]

  /// Optional. The runtime log config for job execution.
  public var loggingConfig: LoggingConfig? = nil

  /// Required. The specification of the main method to call to drive the job.
  /// 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
  /// [jarFileUris][google.cloud.dataproc.v1.SparkJob.jar_file_uris], and then
  /// specify the main class name in
  /// [mainClass][google.cloud.dataproc.v1.SparkJob.main_class].
  ///
  /// [google.cloud.dataproc.v1.SparkJob.jar_file_uris]: <doc:SparkJob/jarFileUris>
  /// [google.cloud.dataproc.v1.SparkJob.main_class]: <doc:SparkJob/mainClass>
  public var driver: OneOf_Driver? = nil

  /// Initialize a new instance of `SparkJob`.
  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 = SparkJob().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"
    case properties = "properties"
    case loggingConfig = "loggingConfig"
  }

  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)
    self.properties = try container.decode([Swift.String: Swift.String].self, forKey: .properties)
    self.loggingConfig = try container.decodeIfPresent(LoggingConfig.self, forKey: .loggingConfig)

    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)
    try container.encode(self.properties, forKey: .properties)
    try container.encode(self.loggingConfig, forKey: .loggingConfig)

    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)
      }
    }
  }

  /// Required. The specification of the main method to call to drive the job.
  /// 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
  /// [jarFileUris][google.cloud.dataproc.v1.SparkJob.jar_file_uris], and then
  /// specify the main class name in
  /// [mainClass][google.cloud.dataproc.v1.SparkJob.main_class].
  ///
  /// [google.cloud.dataproc.v1.SparkJob.jar_file_uris]: <doc:SparkJob/jarFileUris>
  /// [google.cloud.dataproc.v1.SparkJob.main_class]: <doc:SparkJob/mainClass>
  public enum OneOf_Driver: Codable, Equatable, Sendable {
    /// The HCFS URI of the jar file that contains the main class.
    case mainJarFileUri(Swift.String)
    /// The name of the driver's main class. The jar file that contains the class
    /// must be in the default CLASSPATH or specified in
    /// SparkJob.jar_file_uris.
    case mainClass(Swift.String)
  }

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