// 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
  import Foundation
  import GoogleCloudWkt

  /// The top-level message returned from the
  /// [StreamingDetectIntent][google.cloud.dialogflow.cx.v3.Sessions.StreamingDetectIntent]
  /// method.
  ///
  /// Multiple response messages can be returned in order:
  ///
  /// *   If the `StreamingDetectIntentRequest.query_input.audio` field was
  ///     set, the first M messages contain `recognition_result`.
  ///     Each `recognition_result` represents a more complete transcript of what
  ///     the user said. The last `recognition_result` has `is_final` set to
  ///     `true`.
  ///
  /// *   If the `StreamingDetectIntentRequest.enable_partial_response` field was
  ///     true, the `detect_intent_response` field is populated for each
  ///     of the following N responses, where 0 <= N <= 5.
  ///     These responses set the
  ///     [DetectIntentResponse.response_type][google.cloud.dialogflow.cx.v3.DetectIntentResponse.response_type]
  ///     field to `PARTIAL`.
  ///
  /// For the last response message, the `detect_intent_response` is fully
  /// populated, and
  /// [DetectIntentResponse.response_type][google.cloud.dialogflow.cx.v3.DetectIntentResponse.response_type]
  /// is set to `FINAL`.
  ///
  /// [google.cloud.dialogflow.cx.v3.DetectIntentResponse.response_type]: <doc:DetectIntentResponse/responseType>
  /// [google.cloud.dialogflow.cx.v3.Sessions.StreamingDetectIntent]: <doc:Sessions/streamingDetectIntent(request:)>
  public struct StreamingDetectIntentResponse: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Debugging info that would get populated when
    /// `StreamingDetectIntentRequest.enable_debugging_info` is set to true.
    public var debuggingInfo: CloudConversationDebuggingInfo? = nil

    /// The output response.
    public var response: OneOf_Response? = nil

    /// Initialize a new instance of `StreamingDetectIntentResponse`.
    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 = StreamingDetectIntentResponse().with { $0.recognitionResult = ... }
    /// ```
    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 recognitionResult = "recognitionResult"
      case detectIntentResponse = "detectIntentResponse"
      case debuggingInfo = "debuggingInfo"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.debuggingInfo = try container.decodeIfPresent(
        CloudConversationDebuggingInfo.self, forKey: .debuggingInfo)

      var response: OneOf_Response? = nil
      let responseCheckAndSet = {
        if response != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'response'"))
        }
        response = $0
      }
      if let recognitionResult = try container.decodeIfPresent(
        StreamingRecognitionResult?.self, forKey: .recognitionResult)
      {
        try responseCheckAndSet(.recognitionResult(recognitionResult))
      }
      if let detectIntentResponse = try container.decodeIfPresent(
        DetectIntentResponse?.self, forKey: .detectIntentResponse)
      {
        try responseCheckAndSet(.detectIntentResponse(detectIntentResponse))
      }
      self.response = response
    }

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

      if let choice = self.response {
        switch choice {
        case .recognitionResult(let value):
          try container.encode(value, forKey: .recognitionResult)
        case .detectIntentResponse(let value):
          try container.encode(value, forKey: .detectIntentResponse)
        }
      }
    }

    /// The output response.
    public enum OneOf_Response: Codable, Equatable, Sendable {
      /// The result of speech recognition.
      indirect case recognitionResult(StreamingRecognitionResult?)
      /// The response from detect intent.
      indirect case detectIntentResponse(DetectIntentResponse?)
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.dialogflow.cx.v3.StreamingDetectIntentResponse"
    }
    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)
    }
  }
#endif
