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

/// Execution configuration for a workload.
public struct ExecutionConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. Service account that used to execute workload.
  public var serviceAccount: Swift.String = Swift.String()

  /// Optional. Tags used for network traffic control.
  public var networkTags: [Swift.String] = []

  /// Optional. The Cloud KMS key to use for encryption.
  public var kmsKey: Swift.String = Swift.String()

  /// Optional. Applies to sessions only. The duration to keep the session alive
  /// while it's idling. Exceeding this threshold causes the session to
  /// terminate. This field cannot be set on a batch workload. Minimum value is
  /// 10 minutes; maximum value is 14 days (see JSON representation of
  /// [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json)).
  /// Defaults to 1 hour if not set.
  /// If both `ttl` and `idle_ttl` are specified for an interactive session,
  /// the conditions are treated as `OR` conditions: the workload will be
  /// terminated when it has been idle for `idle_ttl` or when `ttl` has been
  /// exceeded, whichever occurs first.
  public var idleTtl: GoogleCloudWkt.Duration? = nil

  /// Optional. The duration after which the workload will be terminated,
  /// specified as the JSON representation for
  /// [Duration](https://protobuf.dev/programming-guides/proto3/#json).
  /// When the workload exceeds this duration, it will be unconditionally
  /// terminated without waiting for ongoing work to finish. If `ttl` is not
  /// specified for a batch workload, the workload will be allowed to run until
  /// it exits naturally (or run forever without exiting). If `ttl` is not
  /// specified for an interactive session, it defaults to 24 hours. If `ttl` is
  /// not specified for a batch that uses 2.1+ runtime version, it defaults to 4
  /// hours. Minimum value is 10 minutes; maximum value is 14 days. If both `ttl`
  /// and `idle_ttl` are specified (for an interactive session), the conditions
  /// are treated as `OR` conditions: the workload will be terminated when it has
  /// been idle for `idle_ttl` or when `ttl` has been exceeded, whichever occurs
  /// first.
  public var ttl: GoogleCloudWkt.Duration? = nil

  /// Optional. A Cloud Storage bucket used to stage workload dependencies,
  /// config files, and store workload output and other ephemeral data, such as
  /// Spark history files. If you do not specify a staging bucket, Cloud Dataproc
  /// will determine a Cloud Storage location according to the region where your
  /// workload is running, and then create and manage project-level, per-location
  /// staging and temporary buckets.
  /// **This field requires a Cloud Storage bucket name, not a `gs://...` URI to
  /// a Cloud Storage bucket.**
  public var stagingBucket: Swift.String = Swift.String()

  /// Optional. Authentication configuration used to set the default identity for
  /// the workload execution. The config specifies the type of identity
  /// (service account or user) that will be used by workloads to access
  /// resources on the project(s).
  public var authenticationConfig: AuthenticationConfig? = nil

  /// Optional. Associates Resource Manager tags with the workload nodes.
  /// There is a max limit of 30 tags.
  /// Keys and values can be either in numeric format, such as
  /// `tagKeys/{tag_key_id}` and `tagValues/{tag_value_id}`, or in namespaced
  /// format, such as `{org_id|project_id}/{tag_key_short_name}` and
  /// `{tag_value_short_name}`.
  public var resourceManagerTags: [Swift.String: Swift.String] = [:]

  /// Network configuration for workload execution.
  public var network: OneOf_Network? = nil

  /// Initialize a new instance of `ExecutionConfig`.
  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 = ExecutionConfig().with { $0.serviceAccount = ... }
  /// ```
  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 serviceAccount = "serviceAccount"
    case networkUri = "networkUri"
    case subnetworkUri = "subnetworkUri"
    case networkTags = "networkTags"
    case kmsKey = "kmsKey"
    case idleTtl = "idleTtl"
    case ttl = "ttl"
    case stagingBucket = "stagingBucket"
    case authenticationConfig = "authenticationConfig"
    case resourceManagerTags = "resourceManagerTags"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.serviceAccount = try container.decode(Swift.String.self, forKey: .serviceAccount)
    self.networkTags = try container.decode([Swift.String].self, forKey: .networkTags)
    self.kmsKey = try container.decode(Swift.String.self, forKey: .kmsKey)
    self.idleTtl = try container.decodeIfPresent(GoogleCloudWkt.Duration.self, forKey: .idleTtl)
    self.ttl = try container.decodeIfPresent(GoogleCloudWkt.Duration.self, forKey: .ttl)
    self.stagingBucket = try container.decode(Swift.String.self, forKey: .stagingBucket)
    self.authenticationConfig = try container.decodeIfPresent(
      AuthenticationConfig.self, forKey: .authenticationConfig)
    self.resourceManagerTags = try container.decode(
      [Swift.String: Swift.String].self, forKey: .resourceManagerTags)

    var network: OneOf_Network? = nil
    let networkCheckAndSet = {
      if network != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'network'"))
      }
      network = $0
    }
    if let networkUri = try container.decodeIfPresent(Swift.String.self, forKey: .networkUri) {
      try networkCheckAndSet(.networkUri(networkUri))
    }
    if let subnetworkUri = try container.decodeIfPresent(Swift.String.self, forKey: .subnetworkUri)
    {
      try networkCheckAndSet(.subnetworkUri(subnetworkUri))
    }
    self.network = network
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.serviceAccount, forKey: .serviceAccount)
    try container.encode(self.networkTags, forKey: .networkTags)
    try container.encode(self.kmsKey, forKey: .kmsKey)
    try container.encode(self.idleTtl, forKey: .idleTtl)
    try container.encode(self.ttl, forKey: .ttl)
    try container.encode(self.stagingBucket, forKey: .stagingBucket)
    try container.encode(self.authenticationConfig, forKey: .authenticationConfig)
    try container.encode(self.resourceManagerTags, forKey: .resourceManagerTags)

    if let choice = self.network {
      switch choice {
      case .networkUri(let value):
        try container.encode(value, forKey: .networkUri)
      case .subnetworkUri(let value):
        try container.encode(value, forKey: .subnetworkUri)
      }
    }
  }

  /// Network configuration for workload execution.
  public enum OneOf_Network: Codable, Equatable, Sendable {
    /// Optional. Network URI to connect workload to.
    case networkUri(Swift.String)
    /// Optional. Subnetwork URI to connect workload to.
    case subnetworkUri(Swift.String)
  }

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