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

#if Sessions || TestCases
  import Foundation

  /// Audio encoding of the audio content sent in the conversational query request.
  /// Refer to the
  /// [Cloud Speech API
  /// documentation](https://cloud.google.com/speech-to-text/docs/basics) for more
  /// details.
  public enum AudioEncoding: Codable, Equatable, Sendable {
    /// Not specified.
    case unspecified
    /// Uncompressed 16-bit signed little-endian samples (Linear PCM).
    /// LINT: LEGACY_NAMES
    case linear16
    /// [`FLAC`](https://xiph.org/flac/documentation.html) (Free Lossless Audio
    /// Codec) is the recommended encoding because it is lossless (therefore
    /// recognition is not compromised) and requires only about half the
    /// bandwidth of `LINEAR16`. `FLAC` stream encoding supports 16-bit and
    /// 24-bit samples, however, not all fields in `STREAMINFO` are supported.
    case flac
    /// 8-bit samples that compand 14-bit audio samples using G.711 PCMU/mu-law.
    case mulaw
    /// Adaptive Multi-Rate Narrowband codec. `sample_rate_hertz` must be 8000.
    case amr
    /// Adaptive Multi-Rate Wideband codec. `sample_rate_hertz` must be 16000.
    case amrWb
    /// Opus encoded audio frames in Ogg container
    /// ([OggOpus](https://wiki.xiph.org/OggOpus)).
    /// `sample_rate_hertz` must be 16000.
    case oggOpus
    /// Although the use of lossy encodings is not recommended, if a very low
    /// bitrate encoding is required, `OGG_OPUS` is highly preferred over
    /// Speex encoding. The [Speex](https://speex.org/) encoding supported by
    /// Dialogflow API has a header byte in each block, as in MIME type
    /// `audio/x-speex-with-header-byte`.
    /// It is a variant of the RTP Speex encoding defined in
    /// [RFC 5574](https://tools.ietf.org/html/rfc5574).
    /// The stream is a sequence of blocks, one block per RTP packet. Each block
    /// starts with a byte containing the length of the block, in bytes, followed
    /// by one or more frames of Speex data, padded to an integral number of
    /// bytes (octets) as specified in RFC 5574. In other words, each RTP header
    /// is replaced with a single byte containing the block length. Only Speex
    /// wideband is supported. `sample_rate_hertz` must be 16000.
    case speexWithHeaderByte
    /// 8-bit samples that compand 13-bit audio samples using G.711 PCMU/a-law.
    case alaw
    /// 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 .linear16: return 1
      case .flac: return 2
      case .mulaw: return 3
      case .amr: return 4
      case .amrWb: return 5
      case .oggOpus: return 6
      case .speexWithHeaderByte: return 7
      case .alaw: return 8
      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 "AUDIO_ENCODING_UNSPECIFIED"
      case .linear16: return "AUDIO_ENCODING_LINEAR_16"
      case .flac: return "AUDIO_ENCODING_FLAC"
      case .mulaw: return "AUDIO_ENCODING_MULAW"
      case .amr: return "AUDIO_ENCODING_AMR"
      case .amrWb: return "AUDIO_ENCODING_AMR_WB"
      case .oggOpus: return "AUDIO_ENCODING_OGG_OPUS"
      case .speexWithHeaderByte: return "AUDIO_ENCODING_SPEEX_WITH_HEADER_BYTE"
      case .alaw: return "AUDIO_ENCODING_ALAW"
      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:AudioEncoding/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "AUDIO_ENCODING_UNSPECIFIED": self = .unspecified
      case "AUDIO_ENCODING_LINEAR_16": self = .linear16
      case "AUDIO_ENCODING_FLAC": self = .flac
      case "AUDIO_ENCODING_MULAW": self = .mulaw
      case "AUDIO_ENCODING_AMR": self = .amr
      case "AUDIO_ENCODING_AMR_WB": self = .amrWb
      case "AUDIO_ENCODING_OGG_OPUS": self = .oggOpus
      case "AUDIO_ENCODING_SPEEX_WITH_HEADER_BYTE": self = .speexWithHeaderByte
      case "AUDIO_ENCODING_ALAW": self = .alaw
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:AudioEncoding/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .linear16
      case 2: self = .flac
      case 3: self = .mulaw
      case 4: self = .amr
      case 5: self = .amrWb
      case 6: self = .oggOpus
      case 7: self = .speexWithHeaderByte
      case 8: self = .alaw
      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 .linear16: return try container.encode(1)
      case .flac: return try container.encode(2)
      case .mulaw: return try container.encode(3)
      case .amr: return try container.encode(4)
      case .amrWb: return try container.encode(5)
      case .oggOpus: return try container.encode(6)
      case .speexWithHeaderByte: return try container.encode(7)
      case .alaw: return try container.encode(8)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }
#endif
