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

/// Represents the metadata of a long-running operation.
public struct OperationMetadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The time the operation was created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// The time the operation was last updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// The resource path for the target of the operation.
  public var resource: Swift.String = Swift.String()

  /// The method that triggered the operation.
  public var method: Swift.String = Swift.String()

  /// The [KMS key
  /// name](https://cloud.google.com/kms/docs/resource-hierarchy#keys) with which
  /// the content of the Operation is encrypted. The expected format is
  /// `projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}`.
  public var kmsKeyName: Swift.String = Swift.String()

  /// The [KMS key version
  /// name](https://cloud.google.com/kms/docs/resource-hierarchy#key_versions)
  /// with which content of the Operation is encrypted. The expected format is
  /// `projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}`.
  public var kmsKeyVersionName: Swift.String = Swift.String()

  /// The percent progress of the Operation. Values can range from 0-100. If the
  /// value is 100, then the operation is finished.
  public var progressPercent: Swift.Int32 = Swift.Int32()

  /// The request that spawned the Operation.
  public var request: OneOf_Request? = nil

  /// Specific metadata per RPC.
  public var metadata: OneOf_Metadata? = nil

  /// Initialize a new instance of `OperationMetadata`.
  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 = OperationMetadata().with { $0.createTime = ... }
  /// ```
  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 createTime = "createTime"
    case updateTime = "updateTime"
    case resource = "resource"
    case method = "method"
    case kmsKeyName = "kmsKeyName"
    case kmsKeyVersionName = "kmsKeyVersionName"
    case batchRecognizeRequest = "batchRecognizeRequest"
    case createRecognizerRequest = "createRecognizerRequest"
    case updateRecognizerRequest = "updateRecognizerRequest"
    case deleteRecognizerRequest = "deleteRecognizerRequest"
    case undeleteRecognizerRequest = "undeleteRecognizerRequest"
    case createCustomClassRequest = "createCustomClassRequest"
    case updateCustomClassRequest = "updateCustomClassRequest"
    case deleteCustomClassRequest = "deleteCustomClassRequest"
    case undeleteCustomClassRequest = "undeleteCustomClassRequest"
    case createPhraseSetRequest = "createPhraseSetRequest"
    case updatePhraseSetRequest = "updatePhraseSetRequest"
    case deletePhraseSetRequest = "deletePhraseSetRequest"
    case undeletePhraseSetRequest = "undeletePhraseSetRequest"
    case updateConfigRequest = "updateConfigRequest"
    case progressPercent = "progressPercent"
    case batchRecognizeMetadata = "batchRecognizeMetadata"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.resource = try container.decode(Swift.String.self, forKey: .resource)
    self.method = try container.decode(Swift.String.self, forKey: .method)
    self.kmsKeyName = try container.decode(Swift.String.self, forKey: .kmsKeyName)
    self.kmsKeyVersionName = try container.decode(Swift.String.self, forKey: .kmsKeyVersionName)
    self.progressPercent = try container.decode(Swift.Int32.self, forKey: .progressPercent)

    var request: OneOf_Request? = nil
    let requestCheckAndSet = {
      if request != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'request'"))
      }
      request = $0
    }
    if let batchRecognizeRequest = try container.decodeIfPresent(
      BatchRecognizeRequest?.self, forKey: .batchRecognizeRequest)
    {
      try requestCheckAndSet(.batchRecognizeRequest(batchRecognizeRequest))
    }
    if let createRecognizerRequest = try container.decodeIfPresent(
      CreateRecognizerRequest?.self, forKey: .createRecognizerRequest)
    {
      try requestCheckAndSet(.createRecognizerRequest(createRecognizerRequest))
    }
    if let updateRecognizerRequest = try container.decodeIfPresent(
      UpdateRecognizerRequest?.self, forKey: .updateRecognizerRequest)
    {
      try requestCheckAndSet(.updateRecognizerRequest(updateRecognizerRequest))
    }
    if let deleteRecognizerRequest = try container.decodeIfPresent(
      DeleteRecognizerRequest?.self, forKey: .deleteRecognizerRequest)
    {
      try requestCheckAndSet(.deleteRecognizerRequest(deleteRecognizerRequest))
    }
    if let undeleteRecognizerRequest = try container.decodeIfPresent(
      UndeleteRecognizerRequest?.self, forKey: .undeleteRecognizerRequest)
    {
      try requestCheckAndSet(.undeleteRecognizerRequest(undeleteRecognizerRequest))
    }
    if let createCustomClassRequest = try container.decodeIfPresent(
      CreateCustomClassRequest?.self, forKey: .createCustomClassRequest)
    {
      try requestCheckAndSet(.createCustomClassRequest(createCustomClassRequest))
    }
    if let updateCustomClassRequest = try container.decodeIfPresent(
      UpdateCustomClassRequest?.self, forKey: .updateCustomClassRequest)
    {
      try requestCheckAndSet(.updateCustomClassRequest(updateCustomClassRequest))
    }
    if let deleteCustomClassRequest = try container.decodeIfPresent(
      DeleteCustomClassRequest?.self, forKey: .deleteCustomClassRequest)
    {
      try requestCheckAndSet(.deleteCustomClassRequest(deleteCustomClassRequest))
    }
    if let undeleteCustomClassRequest = try container.decodeIfPresent(
      UndeleteCustomClassRequest?.self, forKey: .undeleteCustomClassRequest)
    {
      try requestCheckAndSet(.undeleteCustomClassRequest(undeleteCustomClassRequest))
    }
    if let createPhraseSetRequest = try container.decodeIfPresent(
      CreatePhraseSetRequest?.self, forKey: .createPhraseSetRequest)
    {
      try requestCheckAndSet(.createPhraseSetRequest(createPhraseSetRequest))
    }
    if let updatePhraseSetRequest = try container.decodeIfPresent(
      UpdatePhraseSetRequest?.self, forKey: .updatePhraseSetRequest)
    {
      try requestCheckAndSet(.updatePhraseSetRequest(updatePhraseSetRequest))
    }
    if let deletePhraseSetRequest = try container.decodeIfPresent(
      DeletePhraseSetRequest?.self, forKey: .deletePhraseSetRequest)
    {
      try requestCheckAndSet(.deletePhraseSetRequest(deletePhraseSetRequest))
    }
    if let undeletePhraseSetRequest = try container.decodeIfPresent(
      UndeletePhraseSetRequest?.self, forKey: .undeletePhraseSetRequest)
    {
      try requestCheckAndSet(.undeletePhraseSetRequest(undeletePhraseSetRequest))
    }
    if let updateConfigRequest = try container.decodeIfPresent(
      UpdateConfigRequest?.self, forKey: .updateConfigRequest)
    {
      try requestCheckAndSet(.updateConfigRequest(updateConfigRequest))
    }
    self.request = request

    var metadata: OneOf_Metadata? = nil
    let metadataCheckAndSet = {
      if metadata != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'metadata'"))
      }
      metadata = $0
    }
    if let batchRecognizeMetadata = try container.decodeIfPresent(
      BatchRecognizeMetadata?.self, forKey: .batchRecognizeMetadata)
    {
      try metadataCheckAndSet(.batchRecognizeMetadata(batchRecognizeMetadata))
    }
    self.metadata = metadata
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.resource, forKey: .resource)
    try container.encode(self.method, forKey: .method)
    try container.encode(self.kmsKeyName, forKey: .kmsKeyName)
    try container.encode(self.kmsKeyVersionName, forKey: .kmsKeyVersionName)
    try container.encode(self.progressPercent, forKey: .progressPercent)

    if let choice = self.request {
      switch choice {
      case .batchRecognizeRequest(let value):
        try container.encode(value, forKey: .batchRecognizeRequest)
      case .createRecognizerRequest(let value):
        try container.encode(value, forKey: .createRecognizerRequest)
      case .updateRecognizerRequest(let value):
        try container.encode(value, forKey: .updateRecognizerRequest)
      case .deleteRecognizerRequest(let value):
        try container.encode(value, forKey: .deleteRecognizerRequest)
      case .undeleteRecognizerRequest(let value):
        try container.encode(value, forKey: .undeleteRecognizerRequest)
      case .createCustomClassRequest(let value):
        try container.encode(value, forKey: .createCustomClassRequest)
      case .updateCustomClassRequest(let value):
        try container.encode(value, forKey: .updateCustomClassRequest)
      case .deleteCustomClassRequest(let value):
        try container.encode(value, forKey: .deleteCustomClassRequest)
      case .undeleteCustomClassRequest(let value):
        try container.encode(value, forKey: .undeleteCustomClassRequest)
      case .createPhraseSetRequest(let value):
        try container.encode(value, forKey: .createPhraseSetRequest)
      case .updatePhraseSetRequest(let value):
        try container.encode(value, forKey: .updatePhraseSetRequest)
      case .deletePhraseSetRequest(let value):
        try container.encode(value, forKey: .deletePhraseSetRequest)
      case .undeletePhraseSetRequest(let value):
        try container.encode(value, forKey: .undeletePhraseSetRequest)
      case .updateConfigRequest(let value):
        try container.encode(value, forKey: .updateConfigRequest)
      }
    }

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

  /// The request that spawned the Operation.
  public enum OneOf_Request: Codable, Equatable, Sendable {
    /// The BatchRecognizeRequest that spawned the Operation.
    indirect case batchRecognizeRequest(BatchRecognizeRequest?)
    /// The CreateRecognizerRequest that spawned the Operation.
    indirect case createRecognizerRequest(CreateRecognizerRequest?)
    /// The UpdateRecognizerRequest that spawned the Operation.
    indirect case updateRecognizerRequest(UpdateRecognizerRequest?)
    /// The DeleteRecognizerRequest that spawned the Operation.
    indirect case deleteRecognizerRequest(DeleteRecognizerRequest?)
    /// The UndeleteRecognizerRequest that spawned the Operation.
    indirect case undeleteRecognizerRequest(UndeleteRecognizerRequest?)
    /// The CreateCustomClassRequest that spawned the Operation.
    indirect case createCustomClassRequest(CreateCustomClassRequest?)
    /// The UpdateCustomClassRequest that spawned the Operation.
    indirect case updateCustomClassRequest(UpdateCustomClassRequest?)
    /// The DeleteCustomClassRequest that spawned the Operation.
    indirect case deleteCustomClassRequest(DeleteCustomClassRequest?)
    /// The UndeleteCustomClassRequest that spawned the Operation.
    indirect case undeleteCustomClassRequest(UndeleteCustomClassRequest?)
    /// The CreatePhraseSetRequest that spawned the Operation.
    indirect case createPhraseSetRequest(CreatePhraseSetRequest?)
    /// The UpdatePhraseSetRequest that spawned the Operation.
    indirect case updatePhraseSetRequest(UpdatePhraseSetRequest?)
    /// The DeletePhraseSetRequest that spawned the Operation.
    indirect case deletePhraseSetRequest(DeletePhraseSetRequest?)
    /// The UndeletePhraseSetRequest that spawned the Operation.
    indirect case undeletePhraseSetRequest(UndeletePhraseSetRequest?)
    /// The UpdateConfigRequest that spawned the Operation.
    @available(*, deprecated)
    indirect case updateConfigRequest(UpdateConfigRequest?)
  }

  /// Specific metadata per RPC.
  public enum OneOf_Metadata: Codable, Equatable, Sendable {
    /// Metadata specific to the BatchRecognize method.
    indirect case batchRecognizeMetadata(BatchRecognizeMetadata?)
  }

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