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

/// Final results for a single file.
public struct BatchRecognizeFileResult: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Error if one was encountered.
  public var error: GoogleRpc.Status? = nil

  public var metadata: RecognitionResponseMetadata? = nil

  /// Deprecated. Use `cloud_storage_result.native_format_uri` instead.
  @available(*, deprecated)
  public var uri: Swift.String = Swift.String()

  /// Deprecated. Use `inline_result.transcript` instead.
  @available(*, deprecated)
  public var transcript: BatchRecognizeResults? = nil

  public var result: OneOf_Result? = nil

  /// Initialize a new instance of `BatchRecognizeFileResult`.
  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 = BatchRecognizeFileResult().with { $0.error = ... }
  /// ```
  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 error = "error"
    case metadata = "metadata"
    case cloudStorageResult = "cloudStorageResult"
    case inlineResult = "inlineResult"
    case uri = "uri"
    case transcript = "transcript"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.error = try container.decodeIfPresent(GoogleRpc.Status.self, forKey: .error)
    self.metadata = try container.decodeIfPresent(
      RecognitionResponseMetadata.self, forKey: .metadata)
    self.uri = try container.decode(Swift.String.self, forKey: .uri)
    self.transcript = try container.decodeIfPresent(BatchRecognizeResults.self, forKey: .transcript)

    var result: OneOf_Result? = nil
    let resultCheckAndSet = {
      if result != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'result'"))
      }
      result = $0
    }
    if let cloudStorageResult = try container.decodeIfPresent(
      CloudStorageResult?.self, forKey: .cloudStorageResult)
    {
      try resultCheckAndSet(.cloudStorageResult(cloudStorageResult))
    }
    if let inlineResult = try container.decodeIfPresent(InlineResult?.self, forKey: .inlineResult) {
      try resultCheckAndSet(.inlineResult(inlineResult))
    }
    self.result = result
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.error, forKey: .error)
    try container.encode(self.metadata, forKey: .metadata)
    try container.encode(self.uri, forKey: .uri)
    try container.encode(self.transcript, forKey: .transcript)

    if let choice = self.result {
      switch choice {
      case .cloudStorageResult(let value):
        try container.encode(value, forKey: .cloudStorageResult)
      case .inlineResult(let value):
        try container.encode(value, forKey: .inlineResult)
      }
    }
  }

  public enum OneOf_Result: Codable, Equatable, Sendable {
    /// Recognition results written to Cloud Storage. This is
    /// populated only when
    /// [GcsOutputConfig][google.cloud.speech.v2.GcsOutputConfig] is set in
    /// the
    /// [RecognitionOutputConfig][[google.cloud.speech.v2.RecognitionOutputConfig].
    ///
    /// [google.cloud.speech.v2.GcsOutputConfig]: <doc:GcsOutputConfig>
    indirect case cloudStorageResult(CloudStorageResult?)
    /// Recognition results. This is populated only when
    /// [InlineOutputConfig][google.cloud.speech.v2.InlineOutputConfig] is set in
    /// the
    /// [RecognitionOutputConfig][[google.cloud.speech.v2.RecognitionOutputConfig].
    ///
    /// [google.cloud.speech.v2.InlineOutputConfig]: <doc:InlineOutputConfig>
    indirect case inlineResult(InlineResult?)
  }

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