// 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 representation of a batch workload in the service.
public struct Batch: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The resource name of the batch.
  public var name: Swift.String = Swift.String()

  /// Output only. A batch UUID (Unique Universal Identifier). The service
  /// generates this value when it creates the batch.
  public var uuid: Swift.String = Swift.String()

  /// Output only. The time when the batch was created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Runtime information about batch execution.
  public var runtimeInfo: RuntimeInfo? = nil

  /// Output only. The state of the batch.
  public var state: Batch.State = Batch.State()

  /// Output only. Batch state details, such as a failure
  /// description if the state is `FAILED`.
  public var stateMessage: Swift.String = Swift.String()

  /// Output only. The time when the batch entered a current state.
  public var stateTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The email address of the user who created the batch.
  public var creator: Swift.String = Swift.String()

  /// Optional. The labels to associate with this batch.
  /// Label **keys** must contain 1 to 63 characters, and must conform to
  /// [RFC 1035](https://www.ietf.org/rfc/rfc1035.txt).
  /// Label **values** may be empty, but, if present, must contain 1 to 63
  /// characters, and must conform to [RFC
  /// 1035](https://www.ietf.org/rfc/rfc1035.txt). No more than 32 labels can be
  /// associated with a batch.
  public var labels: [Swift.String: Swift.String] = [:]

  /// Optional. Runtime configuration for the batch execution.
  public var runtimeConfig: RuntimeConfig? = nil

  /// Optional. Environment configuration for the batch execution.
  public var environmentConfig: EnvironmentConfig? = nil

  /// Output only. The resource name of the operation associated with this batch.
  public var operation: Swift.String = Swift.String()

  /// Output only. Historical state information for the batch.
  public var stateHistory: [Batch.StateHistory] = []

  /// The application/framework-specific portion of the batch configuration.
  public var batchConfig: OneOf_BatchConfig? = nil

  /// Initialize a new instance of `Batch`.
  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 = Batch().with { $0.name = ... }
  /// ```
  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 name = "name"
    case uuid = "uuid"
    case createTime = "createTime"
    case pysparkBatch = "pysparkBatch"
    case sparkBatch = "sparkBatch"
    case sparkRBatch = "sparkRBatch"
    case sparkSqlBatch = "sparkSqlBatch"
    case pysparkNotebookBatch = "pysparkNotebookBatch"
    case runtimeInfo = "runtimeInfo"
    case state = "state"
    case stateMessage = "stateMessage"
    case stateTime = "stateTime"
    case creator = "creator"
    case labels = "labels"
    case runtimeConfig = "runtimeConfig"
    case environmentConfig = "environmentConfig"
    case operation = "operation"
    case stateHistory = "stateHistory"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.uuid = try container.decode(Swift.String.self, forKey: .uuid)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.runtimeInfo = try container.decodeIfPresent(RuntimeInfo.self, forKey: .runtimeInfo)
    self.state = try container.decode(Batch.State.self, forKey: .state)
    self.stateMessage = try container.decode(Swift.String.self, forKey: .stateMessage)
    self.stateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .stateTime)
    self.creator = try container.decode(Swift.String.self, forKey: .creator)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)
    self.runtimeConfig = try container.decodeIfPresent(RuntimeConfig.self, forKey: .runtimeConfig)
    self.environmentConfig = try container.decodeIfPresent(
      EnvironmentConfig.self, forKey: .environmentConfig)
    self.operation = try container.decode(Swift.String.self, forKey: .operation)
    self.stateHistory = try container.decode([Batch.StateHistory].self, forKey: .stateHistory)

    var batchConfig: OneOf_BatchConfig? = nil
    let batchConfigCheckAndSet = {
      if batchConfig != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'batchConfig'"))
      }
      batchConfig = $0
    }
    if let pysparkBatch = try container.decodeIfPresent(PySparkBatch?.self, forKey: .pysparkBatch) {
      try batchConfigCheckAndSet(.pysparkBatch(pysparkBatch))
    }
    if let sparkBatch = try container.decodeIfPresent(SparkBatch?.self, forKey: .sparkBatch) {
      try batchConfigCheckAndSet(.sparkBatch(sparkBatch))
    }
    if let sparkRBatch = try container.decodeIfPresent(SparkRBatch?.self, forKey: .sparkRBatch) {
      try batchConfigCheckAndSet(.sparkRBatch(sparkRBatch))
    }
    if let sparkSqlBatch = try container.decodeIfPresent(
      SparkSqlBatch?.self, forKey: .sparkSqlBatch)
    {
      try batchConfigCheckAndSet(.sparkSqlBatch(sparkSqlBatch))
    }
    if let pysparkNotebookBatch = try container.decodeIfPresent(
      PySparkNotebookBatch?.self, forKey: .pysparkNotebookBatch)
    {
      try batchConfigCheckAndSet(.pysparkNotebookBatch(pysparkNotebookBatch))
    }
    self.batchConfig = batchConfig
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.name, forKey: .name)
    try container.encode(self.uuid, forKey: .uuid)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.runtimeInfo, forKey: .runtimeInfo)
    try container.encode(self.state, forKey: .state)
    try container.encode(self.stateMessage, forKey: .stateMessage)
    try container.encode(self.stateTime, forKey: .stateTime)
    try container.encode(self.creator, forKey: .creator)
    try container.encode(self.labels, forKey: .labels)
    try container.encode(self.runtimeConfig, forKey: .runtimeConfig)
    try container.encode(self.environmentConfig, forKey: .environmentConfig)
    try container.encode(self.operation, forKey: .operation)
    try container.encode(self.stateHistory, forKey: .stateHistory)

    if let choice = self.batchConfig {
      switch choice {
      case .pysparkBatch(let value):
        try container.encode(value, forKey: .pysparkBatch)
      case .sparkBatch(let value):
        try container.encode(value, forKey: .sparkBatch)
      case .sparkRBatch(let value):
        try container.encode(value, forKey: .sparkRBatch)
      case .sparkSqlBatch(let value):
        try container.encode(value, forKey: .sparkSqlBatch)
      case .pysparkNotebookBatch(let value):
        try container.encode(value, forKey: .pysparkNotebookBatch)
      }
    }
  }

  /// Historical state information.
  public struct StateHistory: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. The state of the batch at this point in history.
    public var state: Batch.State = Batch.State()

    /// Output only. Details about the state at this point in history.
    public var stateMessage: Swift.String = Swift.String()

    /// Output only. The time when the batch entered the historical state.
    public var stateStartTime: GoogleCloudWkt.Timestamp? = nil

    /// Initialize a new instance of `StateHistory`.
    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 = StateHistory().with { $0.state = ... }
    /// ```
    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.dataproc.v1.Batch.StateHistory"
    }
    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 batch state.
  public enum State: Codable, Equatable, Sendable {
    /// The batch state is unknown.
    case unspecified
    /// The batch is created before running.
    case pending
    /// The batch is running.
    case running
    /// The batch is cancelling.
    case cancelling
    /// The batch cancellation was successful.
    case cancelled
    /// The batch completed successfully.
    case succeeded
    /// The batch is no longer running due to an error.
    case failed
    /// Encodes an unknown integer value.
    ///
    /// The most common cause for an unknown values is for the service to send
    /// a value unknown to the library. We recommend you update your library to
    /// the latest version.
    case unknownIntValue(Int)
    /// Encodes an unknown string value.
    ///
    /// The most common cause for an unknown values is for the service to send
    /// a value unknown to the library. We recommend you update your library to
    /// the latest version.
    case unknownStringValue(String)

    public init() {
      self = .unspecified
    }

    /// Returns the integer value associated with the enumeration.
    ///
    /// If the enumeration was initialized with an unknown string value, this returns `nil`.
    public var intValue: Int? {
      switch self {
      case .unspecified: return 0
      case .pending: return 1
      case .running: return 2
      case .cancelling: return 3
      case .cancelled: return 4
      case .succeeded: return 5
      case .failed: return 6
      case .unknownIntValue(let v): return v
      case .unknownStringValue: return nil
      }
    }

    /// Returns the string value (or name) associated with the enumeration.
    ///
    /// If the enumeration was initialized with an unknown integer value, this returns `nil`.
    public var stringValue: Swift.String? {
      switch self {
      case .unspecified: return "STATE_UNSPECIFIED"
      case .pending: return "PENDING"
      case .running: return "RUNNING"
      case .cancelling: return "CANCELLING"
      case .cancelled: return "CANCELLED"
      case .succeeded: return "SUCCEEDED"
      case .failed: return "FAILED"
      case .unknownIntValue: return nil
      case .unknownStringValue(let v): return v
      }
    }

    /// Initialize from a string value.
    ///
    /// If the value is unknown, this initializes to [`unknownStringValue`](doc:State/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "STATE_UNSPECIFIED": self = .unspecified
      case "PENDING": self = .pending
      case "RUNNING": self = .running
      case "CANCELLING": self = .cancelling
      case "CANCELLED": self = .cancelled
      case "SUCCEEDED": self = .succeeded
      case "FAILED": self = .failed
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .pending
      case 2: self = .running
      case 3: self = .cancelling
      case 4: self = .cancelled
      case 5: self = .succeeded
      case 6: self = .failed
      default: self = .unknownIntValue(intValue)
      }
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.singleValueContainer()
      if let v = try? container.decode(Int.self) {
        self.init(intValue: v)
        return
      }
      if let s = try? container.decode(String.self) {
        if let v = Int(s) {
          self.init(intValue: v)
        } else {
          self.init(stringValue: s)
        }
        return
      }
      throw DecodingError.dataCorruptedError(
        in: container, debugDescription: "Expected enum value, must be integer or string.")
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.singleValueContainer()
      switch self {
      case .unspecified: return try container.encode(0)
      case .pending: return try container.encode(1)
      case .running: return try container.encode(2)
      case .cancelling: return try container.encode(3)
      case .cancelled: return try container.encode(4)
      case .succeeded: return try container.encode(5)
      case .failed: return try container.encode(6)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// The application/framework-specific portion of the batch configuration.
  public enum OneOf_BatchConfig: Codable, Equatable, Sendable {
    /// Optional. PySpark batch config.
    indirect case pysparkBatch(PySparkBatch?)
    /// Optional. Spark batch config.
    indirect case sparkBatch(SparkBatch?)
    /// Optional. SparkR batch config.
    indirect case sparkRBatch(SparkRBatch?)
    /// Optional. SparkSql batch config.
    indirect case sparkSqlBatch(SparkSqlBatch?)
    /// Optional. PySpark notebook batch config.
    indirect case pysparkNotebookBatch(PySparkNotebookBatch?)
  }

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