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

/// DeployJobRun contains information specific to a deploy `JobRun`.
public struct DeployJobRun: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The resource name of the Cloud Build `Build` object that is
  /// used to deploy. Format is
  /// `projects/{project}/locations/{location}/builds/{build}`.
  public var build: Swift.String = Swift.String()

  /// Output only. The reason the deploy failed. This will always be unspecified
  /// while the deploy is in progress or if it succeeded.
  public var failureCause: DeployJobRun.FailureCause = DeployJobRun.FailureCause()

  /// Output only. Additional information about the deploy failure, if available.
  public var failureMessage: Swift.String = Swift.String()

  /// Output only. Metadata containing information about the deploy job run.
  public var metadata: DeployJobRunMetadata? = nil

  /// Output only. The artifact of a deploy job run, if available.
  public var artifact: DeployArtifact? = nil

  /// Initialize a new instance of `DeployJobRun`.
  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 = DeployJobRun().with { $0.build = ... }
  /// ```
  public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
    var copy = self
    try config(&copy)
    return copy
  }

  /// Well-known deploy failures.
  public enum FailureCause: Codable, Equatable, Sendable {
    /// No reason for failure is specified.
    case unspecified
    /// Cloud Build is not available, either because it is not enabled or because
    /// Cloud Deploy has insufficient permissions. See [Required
    /// permission](https://cloud.google.com/deploy/docs/cloud-deploy-service-account#required_permissions).
    case cloudBuildUnavailable
    /// The deploy operation did not complete successfully; check Cloud Build
    /// logs.
    case executionFailed
    /// The deploy job run did not complete within the allotted time.
    case deadlineExceeded
    /// There were missing resources in the runtime environment required for a
    /// canary deployment. Check the Cloud Build logs for more information.
    case missingResourcesForCanary
    /// Cloud Build failed to fulfill Cloud Deploy's request. See failure_message
    /// for additional details.
    case cloudBuildRequestFailed
    /// The deploy operation had a feature configured that is not supported.
    case deployFeatureNotSupported
    /// 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 .cloudBuildUnavailable: return 1
      case .executionFailed: return 2
      case .deadlineExceeded: return 3
      case .missingResourcesForCanary: return 4
      case .cloudBuildRequestFailed: return 5
      case .deployFeatureNotSupported: 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 "FAILURE_CAUSE_UNSPECIFIED"
      case .cloudBuildUnavailable: return "CLOUD_BUILD_UNAVAILABLE"
      case .executionFailed: return "EXECUTION_FAILED"
      case .deadlineExceeded: return "DEADLINE_EXCEEDED"
      case .missingResourcesForCanary: return "MISSING_RESOURCES_FOR_CANARY"
      case .cloudBuildRequestFailed: return "CLOUD_BUILD_REQUEST_FAILED"
      case .deployFeatureNotSupported: return "DEPLOY_FEATURE_NOT_SUPPORTED"
      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:FailureCause/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "FAILURE_CAUSE_UNSPECIFIED": self = .unspecified
      case "CLOUD_BUILD_UNAVAILABLE": self = .cloudBuildUnavailable
      case "EXECUTION_FAILED": self = .executionFailed
      case "DEADLINE_EXCEEDED": self = .deadlineExceeded
      case "MISSING_RESOURCES_FOR_CANARY": self = .missingResourcesForCanary
      case "CLOUD_BUILD_REQUEST_FAILED": self = .cloudBuildRequestFailed
      case "DEPLOY_FEATURE_NOT_SUPPORTED": self = .deployFeatureNotSupported
      default: self = .unknownStringValue(stringValue)
      }
    }

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

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