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

/// Workflow program to be executed by Workflows.
public struct Workflow: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The resource name of the workflow.
  /// Format: projects/{project}/locations/{location}/workflows/{workflow}.
  /// This is a workflow-wide field and is not tied to a specific revision.
  public var name: Swift.String = Swift.String()

  /// Description of the workflow provided by the user.
  /// Must be at most 1000 Unicode characters long.
  /// This is a workflow-wide field and is not tied to a specific revision.
  public var description: Swift.String = Swift.String()

  /// Output only. State of the workflow deployment.
  public var state: Workflow.State = Workflow.State()

  /// Output only. The revision of the workflow.
  /// A new revision of a workflow is created as a result of updating the
  /// following properties of a workflow:
  ///
  /// - [Service account][google.cloud.workflows.v1.Workflow.service_account]
  /// - [Workflow code to be
  /// executed][google.cloud.workflows.v1.Workflow.source_contents]
  ///
  /// The format is "000001-a4d", where the first six characters define
  /// the zero-padded revision ordinal number. They are followed by a hyphen and
  /// three hexadecimal random characters.
  ///
  /// [google.cloud.workflows.v1.Workflow.service_account]: <doc:Workflow/serviceAccount>
  /// [google.cloud.workflows.v1.Workflow.source_contents]: <doc:Workflow/sourceContents>
  public var revisionId: Swift.String = Swift.String()

  /// Output only. The timestamp for when the workflow was created.
  /// This is a workflow-wide field and is not tied to a specific revision.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The timestamp for when the workflow was last updated.
  /// This is a workflow-wide field and is not tied to a specific revision.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The timestamp for the latest revision of the workflow's
  /// creation.
  public var revisionCreateTime: GoogleCloudWkt.Timestamp? = nil

  /// Labels associated with this workflow.
  /// Labels can contain at most 64 entries. Keys and values can be no longer
  /// than 63 characters and can only contain lowercase letters, numeric
  /// characters, underscores, and dashes. Label keys must start with a letter.
  /// International characters are allowed.
  /// This is a workflow-wide field and is not tied to a specific revision.
  public var labels: [Swift.String: Swift.String] = [:]

  /// The service account associated with the latest workflow version.
  /// This service account represents the identity of the workflow and determines
  /// what permissions the workflow has.
  /// Format: projects/{project}/serviceAccounts/{account} or {account}
  ///
  /// Using `-` as a wildcard for the `{project}` or not providing one at all
  /// will infer the project from the account. The `{account}` value can be the
  /// `email` address or the `unique_id` of the service account.
  ///
  /// If not provided, workflow will use the project's default service account.
  /// Modifying this field for an existing workflow results in a new workflow
  /// revision.
  public var serviceAccount: Swift.String = Swift.String()

  /// Optional. The resource name of a KMS crypto key used to encrypt or decrypt
  /// the data associated with the workflow.
  ///
  /// Format:
  /// projects/{project}/locations/{location}/keyRings/{keyRing}/cryptoKeys/{cryptoKey}
  ///
  /// Using `-` as a wildcard for the `{project}` or not providing one at all
  /// will infer the project from the account.
  ///
  /// If not provided, data associated with the workflow will not be
  /// CMEK-encrypted.
  public var cryptoKeyName: Swift.String = Swift.String()

  /// Output only. Error regarding the state of the workflow. For example, this
  /// field will have error details if the execution data is unavailable due to
  /// revoked KMS key permissions.
  public var stateError: Workflow.StateError? = nil

  /// Optional. Describes the level of platform logging to apply to calls and
  /// call responses during executions of this workflow. If both the workflow and
  /// the execution specify a logging level, the execution level takes
  /// precedence.
  public var callLogLevel: Workflow.CallLogLevel = Workflow.CallLogLevel()

  /// Optional. User-defined environment variables associated with this workflow
  /// revision. This map has a maximum length of 20. Each string can take up to
  /// 4KiB. Keys cannot be empty strings and cannot start with "GOOGLE" or
  /// "WORKFLOWS".
  public var userEnvVars: [Swift.String: Swift.String] = [:]

  /// Optional. Describes the execution history level to apply to this workflow.
  public var executionHistoryLevel: ExecutionHistoryLevel = ExecutionHistoryLevel()

  /// Output only. A list of all KMS crypto keys used to encrypt or decrypt the
  /// data associated with the workflow.
  public var allKmsKeys: [Swift.String] = []

  /// Output only. A list of all KMS crypto key versions used to encrypt or
  /// decrypt the data associated with the workflow.
  public var allKmsKeysVersions: [Swift.String] = []

  /// Output only. The resource name of a KMS crypto key version used to encrypt
  /// or decrypt the data associated with the workflow.
  ///
  /// Format:
  /// projects/{project}/locations/{location}/keyRings/{keyRing}/cryptoKeys/{cryptoKey}/cryptoKeyVersions/{cryptoKeyVersion}
  public var cryptoKeyVersion: Swift.String = Swift.String()

  /// Optional. Input only. Immutable. Tags associated with this workflow.
  public var tags: [Swift.String: Swift.String] = [:]

  /// Required. Location of the workflow source code.
  /// Modifying this field for an existing workflow results in a new workflow
  /// revision.
  public var sourceCode: OneOf_SourceCode? = nil

  /// Initialize a new instance of `Workflow`.
  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 = Workflow().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 description = "description"
    case state = "state"
    case revisionId = "revisionId"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case revisionCreateTime = "revisionCreateTime"
    case labels = "labels"
    case serviceAccount = "serviceAccount"
    case sourceContents = "sourceContents"
    case cryptoKeyName = "cryptoKeyName"
    case stateError = "stateError"
    case callLogLevel = "callLogLevel"
    case userEnvVars = "userEnvVars"
    case executionHistoryLevel = "executionHistoryLevel"
    case allKmsKeys = "allKmsKeys"
    case allKmsKeysVersions = "allKmsKeysVersions"
    case cryptoKeyVersion = "cryptoKeyVersion"
    case tags = "tags"
  }

  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.description = try container.decode(Swift.String.self, forKey: .description)
    self.state = try container.decode(Workflow.State.self, forKey: .state)
    self.revisionId = try container.decode(Swift.String.self, forKey: .revisionId)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.revisionCreateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .revisionCreateTime)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)
    self.serviceAccount = try container.decode(Swift.String.self, forKey: .serviceAccount)
    self.cryptoKeyName = try container.decode(Swift.String.self, forKey: .cryptoKeyName)
    self.stateError = try container.decodeIfPresent(Workflow.StateError.self, forKey: .stateError)
    self.callLogLevel = try container.decode(Workflow.CallLogLevel.self, forKey: .callLogLevel)
    self.userEnvVars = try container.decode([Swift.String: Swift.String].self, forKey: .userEnvVars)
    self.executionHistoryLevel = try container.decode(
      ExecutionHistoryLevel.self, forKey: .executionHistoryLevel)
    self.allKmsKeys = try container.decode([Swift.String].self, forKey: .allKmsKeys)
    self.allKmsKeysVersions = try container.decode([Swift.String].self, forKey: .allKmsKeysVersions)
    self.cryptoKeyVersion = try container.decode(Swift.String.self, forKey: .cryptoKeyVersion)
    self.tags = try container.decode([Swift.String: Swift.String].self, forKey: .tags)

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

  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.description, forKey: .description)
    try container.encode(self.state, forKey: .state)
    try container.encode(self.revisionId, forKey: .revisionId)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.revisionCreateTime, forKey: .revisionCreateTime)
    try container.encode(self.labels, forKey: .labels)
    try container.encode(self.serviceAccount, forKey: .serviceAccount)
    try container.encode(self.cryptoKeyName, forKey: .cryptoKeyName)
    try container.encode(self.stateError, forKey: .stateError)
    try container.encode(self.callLogLevel, forKey: .callLogLevel)
    try container.encode(self.userEnvVars, forKey: .userEnvVars)
    try container.encode(self.executionHistoryLevel, forKey: .executionHistoryLevel)
    try container.encode(self.allKmsKeys, forKey: .allKmsKeys)
    try container.encode(self.allKmsKeysVersions, forKey: .allKmsKeysVersions)
    try container.encode(self.cryptoKeyVersion, forKey: .cryptoKeyVersion)
    try container.encode(self.tags, forKey: .tags)

    if let choice = self.sourceCode {
      switch choice {
      case .sourceContents(let value):
        try container.encode(value, forKey: .sourceContents)
      }
    }
  }

  /// Describes an error related to the current state of the workflow.
  public struct StateError: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Provides specifics about the error.
    public var details: Swift.String = Swift.String()

    /// The type of this state error.
    public var type: Workflow.StateError.Type_ = Workflow.StateError.Type_()

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

    /// Describes the possibled types of a state error.
    public enum Type_: Codable, Equatable, Sendable {
      /// No type specified.
      case unspecified
      /// Caused by an issue with KMS.
      case kmsError
      /// 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 .kmsError: return 1
        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 "TYPE_UNSPECIFIED"
        case .kmsError: return "KMS_ERROR"
        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:Type_/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "TYPE_UNSPECIFIED": self = .unspecified
        case "KMS_ERROR": self = .kmsError
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Type_/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .kmsError
        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 .kmsError: return try container.encode(1)
        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.workflows.v1.Workflow.StateError"
    }
    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)
    }
  }

  /// Describes the current state of workflow deployment.
  public enum State: Codable, Equatable, Sendable {
    /// Invalid state.
    case unspecified
    /// The workflow has been deployed successfully and is serving.
    case active
    /// Workflow data is unavailable. See the `state_error` field.
    case unavailable
    /// 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 .active: return 1
      case .unavailable: return 2
      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 .active: return "ACTIVE"
      case .unavailable: return "UNAVAILABLE"
      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 "ACTIVE": self = .active
      case "UNAVAILABLE": self = .unavailable
      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 = .active
      case 2: self = .unavailable
      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 .active: return try container.encode(1)
      case .unavailable: return try container.encode(2)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// Describes the level of platform logging to apply to calls and call
  /// responses during workflow executions.
  public enum CallLogLevel: Codable, Equatable, Sendable {
    /// No call logging level specified.
    case unspecified
    /// Log all call steps within workflows, all call returns, and all exceptions
    /// raised.
    case logAllCalls
    /// Log only exceptions that are raised from call steps within workflows.
    case logErrorsOnly
    /// Explicitly log nothing.
    case logNone
    /// 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 .logAllCalls: return 1
      case .logErrorsOnly: return 2
      case .logNone: return 3
      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 "CALL_LOG_LEVEL_UNSPECIFIED"
      case .logAllCalls: return "LOG_ALL_CALLS"
      case .logErrorsOnly: return "LOG_ERRORS_ONLY"
      case .logNone: return "LOG_NONE"
      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:CallLogLevel/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "CALL_LOG_LEVEL_UNSPECIFIED": self = .unspecified
      case "LOG_ALL_CALLS": self = .logAllCalls
      case "LOG_ERRORS_ONLY": self = .logErrorsOnly
      case "LOG_NONE": self = .logNone
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  /// Required. Location of the workflow source code.
  /// Modifying this field for an existing workflow results in a new workflow
  /// revision.
  public enum OneOf_SourceCode: Codable, Equatable, Sendable {
    /// Workflow code to be executed. The size limit is 128KB.
    case sourceContents(Swift.String)
  }

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