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

/// Metadata about a single file in a batch for BatchRecognize.
public struct BatchRecognizeFileMetadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Features and audio metadata to use for the Automatic Speech Recognition.
  /// This field in combination with the
  /// [config_mask][google.cloud.speech.v2.BatchRecognizeFileMetadata.config_mask]
  /// field can be used to override parts of the
  /// [default_recognition_config][google.cloud.speech.v2.Recognizer.default_recognition_config]
  /// of the Recognizer resource as well as the
  /// [config][google.cloud.speech.v2.BatchRecognizeRequest.config] at the
  /// request level.
  ///
  /// [google.cloud.speech.v2.BatchRecognizeFileMetadata.config_mask]: <doc:BatchRecognizeFileMetadata/configMask>
  /// [google.cloud.speech.v2.BatchRecognizeRequest.config]: <doc:BatchRecognizeRequest/config>
  /// [google.cloud.speech.v2.Recognizer.default_recognition_config]: <doc:Recognizer/defaultRecognitionConfig>
  public var config: RecognitionConfig? = nil

  /// The list of fields in
  /// [config][google.cloud.speech.v2.BatchRecognizeFileMetadata.config] that
  /// override the values in the
  /// [default_recognition_config][google.cloud.speech.v2.Recognizer.default_recognition_config]
  /// of the recognizer during this recognition request. If no mask is provided,
  /// all non-default valued fields in
  /// [config][google.cloud.speech.v2.BatchRecognizeFileMetadata.config] override
  /// the values in the recognizer for this recognition request. If a mask is
  /// provided, only the fields listed in the mask override the config in the
  /// recognizer for this recognition request. If a wildcard (`*`) is provided,
  /// [config][google.cloud.speech.v2.BatchRecognizeFileMetadata.config]
  /// completely overrides and replaces the config in the recognizer for this
  /// recognition request.
  ///
  /// [google.cloud.speech.v2.BatchRecognizeFileMetadata.config]: <doc:BatchRecognizeFileMetadata/config>
  /// [google.cloud.speech.v2.Recognizer.default_recognition_config]: <doc:Recognizer/defaultRecognitionConfig>
  public var configMask: GoogleCloudWkt.FieldMask? = nil

  /// The audio source, which is a Google Cloud Storage URI.
  public var audioSource: OneOf_AudioSource? = nil

  /// Initialize a new instance of `BatchRecognizeFileMetadata`.
  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 = BatchRecognizeFileMetadata().with { $0.uri = ... }
  /// ```
  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 uri = "uri"
    case config = "config"
    case configMask = "configMask"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.config = try container.decodeIfPresent(RecognitionConfig.self, forKey: .config)
    self.configMask = try container.decodeIfPresent(
      GoogleCloudWkt.FieldMask.self, forKey: .configMask)

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

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.config, forKey: .config)
    try container.encode(self.configMask, forKey: .configMask)

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

  /// The audio source, which is a Google Cloud Storage URI.
  public enum OneOf_AudioSource: Codable, Equatable, Sendable {
    /// Cloud Storage URI for the audio file.
    case uri(Swift.String)
  }

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