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

/// Configuration of the environment to use when calling Skaffold.
public struct ExecutionConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Usages when this configuration should be applied.
  public var usages: [ExecutionConfig.ExecutionEnvironmentUsage] = []

  /// Optional. The resource name of the `WorkerPool`, with the format
  /// `projects/{project}/locations/{location}/workerPools/{worker_pool}`.
  /// If this optional field is unspecified, the default Cloud Build pool will be
  /// used.
  public var workerPool: Swift.String = Swift.String()

  /// Optional. Google service account to use for execution. If unspecified,
  /// the project execution service account
  /// (<PROJECT_NUMBER>-compute@developer.gserviceaccount.com) is used.
  public var serviceAccount: Swift.String = Swift.String()

  /// Optional. Cloud Storage location in which to store execution outputs. This
  /// can either be a bucket ("gs://my-bucket") or a path within a bucket
  /// ("gs://my-bucket/my-dir").
  /// If unspecified, a default bucket located in the same region will be used.
  public var artifactStorage: Swift.String = Swift.String()

  /// Optional. Execution timeout for a Cloud Build Execution. This must be
  /// between 10m and 24h in seconds format. If unspecified, a default timeout of
  /// 1h is used.
  public var executionTimeout: GoogleCloudWkt.Duration? = nil

  /// Optional. If true, additional logging will be enabled when running builds
  /// in this execution environment.
  public var verbose: Swift.Bool = Swift.Bool()

  /// Details of the environment.
  public var executionEnvironment: OneOf_ExecutionEnvironment? = 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.usages = ... }
  /// ```
  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 usages = "usages"
    case defaultPool = "defaultPool"
    case privatePool = "privatePool"
    case workerPool = "workerPool"
    case serviceAccount = "serviceAccount"
    case artifactStorage = "artifactStorage"
    case executionTimeout = "executionTimeout"
    case verbose = "verbose"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.usages = try container.decode(
      [ExecutionConfig.ExecutionEnvironmentUsage].self, forKey: .usages)
    self.workerPool = try container.decode(Swift.String.self, forKey: .workerPool)
    self.serviceAccount = try container.decode(Swift.String.self, forKey: .serviceAccount)
    self.artifactStorage = try container.decode(Swift.String.self, forKey: .artifactStorage)
    self.executionTimeout = try container.decodeIfPresent(
      GoogleCloudWkt.Duration.self, forKey: .executionTimeout)
    self.verbose = try container.decode(Swift.Bool.self, forKey: .verbose)

    var executionEnvironment: OneOf_ExecutionEnvironment? = nil
    let executionEnvironmentCheckAndSet = {
      if executionEnvironment != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'executionEnvironment'"))
      }
      executionEnvironment = $0
    }
    if let defaultPool = try container.decodeIfPresent(DefaultPool?.self, forKey: .defaultPool) {
      try executionEnvironmentCheckAndSet(.defaultPool(defaultPool))
    }
    if let privatePool = try container.decodeIfPresent(PrivatePool?.self, forKey: .privatePool) {
      try executionEnvironmentCheckAndSet(.privatePool(privatePool))
    }
    self.executionEnvironment = executionEnvironment
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.usages, forKey: .usages)
    try container.encode(self.workerPool, forKey: .workerPool)
    try container.encode(self.serviceAccount, forKey: .serviceAccount)
    try container.encode(self.artifactStorage, forKey: .artifactStorage)
    try container.encode(self.executionTimeout, forKey: .executionTimeout)
    try container.encode(self.verbose, forKey: .verbose)

    if let choice = self.executionEnvironment {
      switch choice {
      case .defaultPool(let value):
        try container.encode(value, forKey: .defaultPool)
      case .privatePool(let value):
        try container.encode(value, forKey: .privatePool)
      }
    }
  }

  /// Possible usages of this configuration.
  public enum ExecutionEnvironmentUsage: Codable, Equatable, Sendable {
    /// Default value. This value is unused.
    case unspecified
    /// Use for rendering.
    case render
    /// Use for deploying and deployment hooks.
    case deploy
    /// Use for deployment verification.
    case verify
    /// Use for predeploy job execution.
    case predeploy
    /// Use for postdeploy job execution.
    case postdeploy
    /// 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 .render: return 1
      case .deploy: return 2
      case .verify: return 3
      case .predeploy: return 4
      case .postdeploy: return 5
      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 "EXECUTION_ENVIRONMENT_USAGE_UNSPECIFIED"
      case .render: return "RENDER"
      case .deploy: return "DEPLOY"
      case .verify: return "VERIFY"
      case .predeploy: return "PREDEPLOY"
      case .postdeploy: return "POSTDEPLOY"
      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:ExecutionEnvironmentUsage/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "EXECUTION_ENVIRONMENT_USAGE_UNSPECIFIED": self = .unspecified
      case "RENDER": self = .render
      case "DEPLOY": self = .deploy
      case "VERIFY": self = .verify
      case "PREDEPLOY": self = .predeploy
      case "POSTDEPLOY": self = .postdeploy
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:ExecutionEnvironmentUsage/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .render
      case 2: self = .deploy
      case 3: self = .verify
      case 4: self = .predeploy
      case 5: self = .postdeploy
      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 .render: return try container.encode(1)
      case .deploy: return try container.encode(2)
      case .verify: return try container.encode(3)
      case .predeploy: return try container.encode(4)
      case .postdeploy: return try container.encode(5)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// Details of the environment.
  public enum OneOf_ExecutionEnvironment: Codable, Equatable, Sendable {
    /// Optional. Use default Cloud Build pool.
    indirect case defaultPool(DefaultPool?)
    /// Optional. Use private Cloud Build pool.
    indirect case privatePool(PrivatePool?)
  }

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