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

/// Configuration to set up audio encoder. The encoding determines the output
/// audio format that we'd like.
public enum AudioEncoding: Codable, Equatable, Sendable {
  /// Not specified. Only used by GenerateVoiceCloningKey. Otherwise, will return
  /// result
  /// [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT].
  case unspecified
  /// Uncompressed 16-bit signed little-endian samples (Linear PCM).
  /// Audio content returned as LINEAR16 also contains a WAV header.
  case linear16
  /// MP3 audio at 32kbps.
  case mp3
  /// Opus encoded audio wrapped in an ogg container. The result is a
  /// file which can be played natively on Android, and in browsers (at least
  /// Chrome and Firefox). The quality of the encoding is considerably higher
  /// than MP3 while using approximately the same bitrate.
  case oggOpus
  /// 8-bit samples that compand 14-bit audio samples using G.711 PCMU/mu-law.
  /// Audio content returned as MULAW also contains a WAV header.
  case mulaw
  /// 8-bit samples that compand 14-bit audio samples using G.711 PCMU/A-law.
  /// Audio content returned as ALAW also contains a WAV header.
  case alaw
  /// Uncompressed 16-bit signed little-endian samples (Linear PCM).
  /// Note that as opposed to LINEAR16, audio won't be wrapped in a WAV (or
  /// any other) header.
  case pcm
  /// M4A audio.
  case m4A
  /// 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 .mp3: return 2
    case .oggOpus: return 3
    case .mulaw: return 5
    case .alaw: return 6
    case .pcm: return 7
    case .m4A: 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 "LINEAR16"
    case .mp3: return "MP3"
    case .oggOpus: return "OGG_OPUS"
    case .mulaw: return "MULAW"
    case .alaw: return "ALAW"
    case .pcm: return "PCM"
    case .m4A: return "M4A"
    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 "LINEAR16": self = .linear16
    case "MP3": self = .mp3
    case "OGG_OPUS": self = .oggOpus
    case "MULAW": self = .mulaw
    case "ALAW": self = .alaw
    case "PCM": self = .pcm
    case "M4A": self = .m4A
    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 = .mp3
    case 3: self = .oggOpus
    case 5: self = .mulaw
    case 6: self = .alaw
    case 7: self = .pcm
    case 8: self = .m4A
    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 .mp3: return try container.encode(2)
    case .oggOpus: return try container.encode(3)
    case .mulaw: return try container.encode(5)
    case .alaw: return try container.encode(6)
    case .pcm: return try container.encode(7)
    case .m4A: return try container.encode(8)
    case .unknownIntValue(let v): return try container.encode(v)
    case .unknownStringValue(let v): return try container.encode(v)
    }
  }
}
