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

/// Runnable describes instructions for executing a specific script or container
/// as part of a Task.
public struct Runnable: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. DisplayName is an optional field that can be provided by the
  /// caller. If provided, it will be used in logs and other outputs to identify
  /// the script, making it easier for users to understand the logs. If not
  /// provided the index of the runnable will be used for outputs.
  public var displayName: Swift.String = Swift.String()

  /// Normally, a runnable that returns a non-zero exit status fails and causes
  /// the task to fail. However, you can set this field to `true` to allow the
  /// task to continue executing its other runnables even if this runnable
  /// fails.
  public var ignoreExitStatus: Swift.Bool = Swift.Bool()

  /// Normally, a runnable that doesn't exit causes its task to fail. However,
  /// you can set this field to `true` to configure a background runnable.
  /// Background runnables are allowed continue running in the background while
  /// the task executes subsequent runnables. For example, background runnables
  /// are useful for providing services to other runnables or providing
  /// debugging-support tools like SSH servers.
  ///
  /// Specifically, background runnables are killed automatically (if they have
  /// not already exited) a short time after all foreground runnables have
  /// completed. Even though this is likely to result in a non-zero exit status
  /// for the background runnable, these automatic kills are not treated as task
  /// failures.
  public var background: Swift.Bool = Swift.Bool()

  /// By default, after a Runnable fails, no further Runnable are executed. This
  /// flag indicates that this Runnable must be run even if the Task has already
  /// failed. This is useful for Runnables that copy output files off of the VM
  /// or for debugging.
  ///
  /// The always_run flag does not override the Task's overall max_run_duration.
  /// If the max_run_duration has expired then no further Runnables will execute,
  /// not even always_run Runnables.
  public var alwaysRun: Swift.Bool = Swift.Bool()

  /// Environment variables for this Runnable (overrides variables set for the
  /// whole Task or TaskGroup).
  public var environment: Environment? = nil

  /// Timeout for this Runnable.
  public var timeout: GoogleCloudWkt.Duration? = nil

  /// Labels for this Runnable.
  public var labels: [Swift.String: Swift.String] = [:]

  /// Required. The script, container, or barrier for this runnable to execute.
  public var executable: OneOf_Executable? = nil

  /// Initialize a new instance of `Runnable`.
  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 = Runnable().with { $0.container = ... }
  /// ```
  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 container = "container"
    case script = "script"
    case barrier = "barrier"
    case displayName = "displayName"
    case ignoreExitStatus = "ignoreExitStatus"
    case background = "background"
    case alwaysRun = "alwaysRun"
    case environment = "environment"
    case timeout = "timeout"
    case labels = "labels"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.displayName = try container.decode(Swift.String.self, forKey: .displayName)
    self.ignoreExitStatus = try container.decode(Swift.Bool.self, forKey: .ignoreExitStatus)
    self.background = try container.decode(Swift.Bool.self, forKey: .background)
    self.alwaysRun = try container.decode(Swift.Bool.self, forKey: .alwaysRun)
    self.environment = try container.decodeIfPresent(Environment.self, forKey: .environment)
    self.timeout = try container.decodeIfPresent(GoogleCloudWkt.Duration.self, forKey: .timeout)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)

    var executable: OneOf_Executable? = nil
    let executableCheckAndSet = {
      if executable != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'executable'"))
      }
      executable = $0
    }
    if let container = try container.decodeIfPresent(Runnable.Container?.self, forKey: .container) {
      try executableCheckAndSet(.container(container))
    }
    if let script = try container.decodeIfPresent(Runnable.Script?.self, forKey: .script) {
      try executableCheckAndSet(.script(script))
    }
    if let barrier = try container.decodeIfPresent(Runnable.Barrier?.self, forKey: .barrier) {
      try executableCheckAndSet(.barrier(barrier))
    }
    self.executable = executable
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.displayName, forKey: .displayName)
    try container.encode(self.ignoreExitStatus, forKey: .ignoreExitStatus)
    try container.encode(self.background, forKey: .background)
    try container.encode(self.alwaysRun, forKey: .alwaysRun)
    try container.encode(self.environment, forKey: .environment)
    try container.encode(self.timeout, forKey: .timeout)
    try container.encode(self.labels, forKey: .labels)

    if let choice = self.executable {
      switch choice {
      case .container(let value):
        try container.encode(value, forKey: .container)
      case .script(let value):
        try container.encode(value, forKey: .script)
      case .barrier(let value):
        try container.encode(value, forKey: .barrier)
      }
    }
  }

  /// Container runnable.
  public struct Container: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The URI to pull the container image from.
    public var imageUri: Swift.String = Swift.String()

    /// Required for some container images. Overrides the `CMD` specified in the
    /// container. If there is an `ENTRYPOINT` (either in the container image or
    /// with the `entrypoint` field below) then these commands are appended as
    /// arguments to the `ENTRYPOINT`.
    public var commands: [Swift.String] = []

    /// Required for some container images. Overrides the `ENTRYPOINT` specified
    /// in the container.
    public var entrypoint: Swift.String = Swift.String()

    /// Volumes to mount (bind mount) from the host machine files or directories
    /// into the container, formatted to match `--volume` option for the
    /// `docker run` command&mdash;for example, `/foo:/bar` or `/foo:/bar:ro`.
    ///
    /// If the `TaskSpec.Volumes` field is specified but this field is not, Batch
    /// will mount each volume from the host machine to the container with the
    /// same mount path by default. In this case, the default mount option for
    /// containers will be read-only (`ro`) for existing persistent disks and
    /// read-write (`rw`) for other volume types, regardless of the original
    /// mount options specified in `TaskSpec.Volumes`. If you need different
    /// mount settings, you can explicitly configure them in this field.
    public var volumes: [Swift.String] = []

    /// Required for some container images. Arbitrary additional options to
    /// include in the `docker run` command when running this container&mdash;for
    /// example, `--network host`. For the `--volume` option, use the `volumes`
    /// field for the container.
    public var options: Swift.String = Swift.String()

    /// If set to true, external network access to and from container will be
    /// blocked, containers that are with block_external_network as true can
    /// still communicate with each other, network cannot be specified in the
    /// `container.options` field.
    public var blockExternalNetwork: Swift.Bool = Swift.Bool()

    /// Required if the container image is from a private Docker registry. The
    /// username to login to the Docker registry that contains the image.
    ///
    /// You can either specify the username directly by using plain text or
    /// specify an encrypted username by using a Secret Manager secret:
    /// `projects/*/secrets/*/versions/*`. However, using a secret is
    /// recommended for enhanced security.
    ///
    /// Caution: If you specify the username using plain text, you risk the
    /// username being exposed to any users who can view the job or its logs.
    /// To avoid this risk, specify a secret that contains the username instead.
    ///
    /// Learn more about [Secret
    /// Manager](https://cloud.google.com/secret-manager/docs/) and [using
    /// Secret Manager with
    /// Batch](https://cloud.google.com/batch/docs/create-run-job-secret-manager).
    public var username: Swift.String = Swift.String()

    /// Required if the container image is from a private Docker registry. The
    /// password to login to the Docker registry that contains the image.
    ///
    /// For security, it is strongly recommended to specify an
    /// encrypted password by using a Secret Manager secret:
    /// `projects/*/secrets/*/versions/*`.
    ///
    /// Warning: If you specify the password using plain text, you risk the
    /// password being exposed to any users who can view the job or its logs.
    /// To avoid this risk, specify a secret that contains the password instead.
    ///
    /// Learn more about [Secret
    /// Manager](https://cloud.google.com/secret-manager/docs/) and [using
    /// Secret Manager with
    /// Batch](https://cloud.google.com/batch/docs/create-run-job-secret-manager).
    public var password: Swift.String = Swift.String()

    /// Optional. If set to true, this container runnable uses Image streaming.
    ///
    /// Use Image streaming to allow the runnable to initialize without
    /// waiting for the entire container image to download, which can
    /// significantly reduce startup time for large container images.
    ///
    /// When `enableImageStreaming` is set to true, the container
    /// runtime is [containerd](https://containerd.io/) instead of Docker.
    /// Additionally, this container runnable only supports the following
    /// `container` subfields: `imageUri`,
    /// `commands[]`, `entrypoint`, and
    /// `volumes[]`; any other `container` subfields are ignored.
    ///
    /// For more information about the requirements and limitations for using
    /// Image streaming with Batch, see the [`image-streaming`
    /// sample on
    /// GitHub](https://github.com/GoogleCloudPlatform/batch-samples/tree/main/api-samples/image-streaming).
    public var enableImageStreaming: Swift.Bool = Swift.Bool()

    /// Initialize a new instance of `Container`.
    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 = Container().with { $0.imageUri = ... }
    /// ```
    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.batch.v1.Runnable.Container"
    }
    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)
    }
  }

  /// Script runnable.
  public struct Script: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The source code for this script runnable.
    public var command: OneOf_Command? = nil

    /// Initialize a new instance of `Script`.
    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 = Script().with { $0.path = ... }
    /// ```
    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 path = "path"
      case text = "text"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)

      var command: OneOf_Command? = nil
      let commandCheckAndSet = {
        if command != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'command'"))
        }
        command = $0
      }
      if let path = try container.decodeIfPresent(Swift.String.self, forKey: .path) {
        try commandCheckAndSet(.path(path))
      }
      if let text = try container.decodeIfPresent(Swift.String.self, forKey: .text) {
        try commandCheckAndSet(.text(text))
      }
      self.command = command
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)

      if let choice = self.command {
        switch choice {
        case .path(let value):
          try container.encode(value, forKey: .path)
        case .text(let value):
          try container.encode(value, forKey: .text)
        }
      }
    }

    /// Required. The source code for this script runnable.
    public enum OneOf_Command: Codable, Equatable, Sendable {
      /// The path to a script file that is accessible from the host VM(s).
      ///
      /// Unless the script file supports the default `#!/bin/sh` shell
      /// interpreter, you must specify an interpreter by including a
      /// [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix) as the
      /// first line of the file. For example, to execute the script using bash,
      /// include `#!/bin/bash` as the first line of the file. Alternatively,
      /// to execute the script using Python3, include `#!/usr/bin/env python3`
      /// as the first line of the file.
      case path(Swift.String)
      /// The text for a script.
      ///
      /// Unless the script text supports the default `#!/bin/sh` shell
      /// interpreter, you must specify an interpreter by including a
      /// [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix) at the
      /// beginning of the text. For example, to execute the script using bash,
      /// include `#!/bin/bash\n` at the beginning of the text. Alternatively,
      /// to execute the script using Python3, include `#!/usr/bin/env python3\n`
      /// at the beginning of the text.
      case text(Swift.String)
    }

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

  /// A barrier runnable automatically blocks the execution of subsequent
  /// runnables until all the tasks in the task group reach the barrier.
  public struct Barrier: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Barriers are identified by their index in runnable list.
    /// Names are not required, but if present should be an identifier.
    public var name: Swift.String = Swift.String()

    /// Initialize a new instance of `Barrier`.
    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 = Barrier().with { $0.name = ... }
    /// ```
    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.batch.v1.Runnable.Barrier"
    }
    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)
    }
  }

  /// Required. The script, container, or barrier for this runnable to execute.
  public enum OneOf_Executable: Codable, Equatable, Sendable {
    /// Container runnable.
    indirect case container(Runnable.Container?)
    /// Script runnable.
    indirect case script(Runnable.Script?)
    /// Barrier runnable.
    indirect case barrier(Runnable.Barrier?)
  }

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