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

/// Input for the session.
public struct SessionInput: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. A flag to indicate if the current message is a fragment of a
  /// larger input in the bidi streaming session.
  ///
  /// When set to `true`, the agent defers processing until it receives a
  /// subsequent message where `will_continue` is `false`, or until the system
  /// detects an endpoint in the audio input.
  ///
  /// NOTE: This field does not apply to audio and DTMF inputs, as they are
  /// always processed automatically based on the endpointing signal.
  public var willContinue: Swift.Bool = Swift.Bool()

  /// The type of the input.
  public var inputType: OneOf_InputType? = nil

  /// Initialize a new instance of `SessionInput`.
  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 = SessionInput().with { $0.text = ... }
  /// ```
  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 text = "text"
    case dtmf = "dtmf"
    case audio = "audio"
    case toolResponses = "toolResponses"
    case image = "image"
    case blob = "blob"
    case variables = "variables"
    case event = "event"
    case willContinue = "willContinue"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.willContinue = try container.decode(Swift.Bool.self, forKey: .willContinue)

    var inputType: OneOf_InputType? = nil
    let inputTypeCheckAndSet = {
      if inputType != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'inputType'"))
      }
      inputType = $0
    }
    if let text = try container.decodeIfPresent(Swift.String.self, forKey: .text) {
      try inputTypeCheckAndSet(.text(text))
    }
    if let dtmf = try container.decodeIfPresent(Swift.String.self, forKey: .dtmf) {
      try inputTypeCheckAndSet(.dtmf(dtmf))
    }
    if let audio = try container.decodeIfPresent(Foundation.Data.self, forKey: .audio) {
      try inputTypeCheckAndSet(.audio(audio))
    }
    if let toolResponses = try container.decodeIfPresent(
      ToolResponses?.self, forKey: .toolResponses)
    {
      try inputTypeCheckAndSet(.toolResponses(toolResponses))
    }
    if let image = try container.decodeIfPresent(Image?.self, forKey: .image) {
      try inputTypeCheckAndSet(.image(image))
    }
    if let blob = try container.decodeIfPresent(Blob?.self, forKey: .blob) {
      try inputTypeCheckAndSet(.blob(blob))
    }
    if let variables = try container.decodeIfPresent(
      GoogleCloudWkt.Struct?.self, forKey: .variables)
    {
      try inputTypeCheckAndSet(.variables(variables))
    }
    if let event = try container.decodeIfPresent(Event?.self, forKey: .event) {
      try inputTypeCheckAndSet(.event(event))
    }
    self.inputType = inputType
  }

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

    if let choice = self.inputType {
      switch choice {
      case .text(let value):
        try container.encode(value, forKey: .text)
      case .dtmf(let value):
        try container.encode(value, forKey: .dtmf)
      case .audio(let value):
        try container.encode(value, forKey: .audio)
      case .toolResponses(let value):
        try container.encode(value, forKey: .toolResponses)
      case .image(let value):
        try container.encode(value, forKey: .image)
      case .blob(let value):
        try container.encode(value, forKey: .blob)
      case .variables(let value):
        try container.encode(value, forKey: .variables)
      case .event(let value):
        try container.encode(value, forKey: .event)
      }
    }
  }

  /// The type of the input.
  public enum OneOf_InputType: Codable, Equatable, Sendable {
    /// Optional. Text data from the end user.
    case text(Swift.String)
    /// Optional. DTMF digits from the end user.
    case dtmf(Swift.String)
    /// Optional. Audio data from the end user.
    case audio(Foundation.Data)
    /// Optional. Execution results for the tool calls from the client.
    indirect case toolResponses(ToolResponses?)
    /// Optional. Image data from the end user.
    indirect case image(Image?)
    /// Optional. Blob data from the end user.
    indirect case blob(Blob?)
    /// Optional. Contextual variables for the session, keyed by name. Only
    /// variables declared in the app will be used by the CES agent.
    ///
    /// Unrecognized variables will still be sent to the [Dialogflow
    /// agent][Agent.RemoteDialogflowAgent] as additional session parameters.
    ///
    /// [Agent.RemoteDialogflowAgent]: <doc:Agent/RemoteDialogflowAgent>
    indirect case variables(GoogleCloudWkt.Struct?)
    /// Optional. Event input.
    indirect case event(Event?)
  }

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