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

/// Represents a widget tool that the agent can invoke. When the tool is chosen
/// by the agent, agent will return the widget to the client. The client is
/// responsible for processing the widget and generating the next user query to
/// continue the interaction with the agent.
public struct WidgetTool: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. The display name of the widget tool.
  public var name: Swift.String = Swift.String()

  /// Optional. The description of the widget tool.
  public var description: Swift.String = Swift.String()

  /// Optional. The type of the widget tool. If not specified, the default type
  /// will be CUSTOMIZED.
  public var widgetType: WidgetTool.WidgetType = WidgetTool.WidgetType()

  /// Optional. Configuration for rendering the widget.
  public var uiConfig: GoogleCloudWkt.Struct? = nil

  /// Optional. The mapping that defines how data from a source tool is mapped to
  /// the widget's input parameters.
  public var dataMapping: WidgetTool.DataMapping? = nil

  /// Optional. Configuration for always-included text responses.
  public var textResponseConfig: WidgetTool.TextResponseConfig? = nil

  /// The input of the widget tool.
  public var input: OneOf_Input? = nil

  /// Initialize a new instance of `WidgetTool`.
  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 = WidgetTool().with { $0.parameters = ... }
  /// ```
  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 parameters = "parameters"
    case name = "name"
    case description = "description"
    case widgetType = "widgetType"
    case uiConfig = "uiConfig"
    case dataMapping = "dataMapping"
    case textResponseConfig = "textResponseConfig"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.widgetType = try container.decode(WidgetTool.WidgetType.self, forKey: .widgetType)
    self.uiConfig = try container.decodeIfPresent(GoogleCloudWkt.Struct.self, forKey: .uiConfig)
    self.dataMapping = try container.decodeIfPresent(
      WidgetTool.DataMapping.self, forKey: .dataMapping)
    self.textResponseConfig = try container.decodeIfPresent(
      WidgetTool.TextResponseConfig.self, forKey: .textResponseConfig)

    var input: OneOf_Input? = nil
    let inputCheckAndSet = {
      if input != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'input'"))
      }
      input = $0
    }
    if let parameters = try container.decodeIfPresent(Schema?.self, forKey: .parameters) {
      try inputCheckAndSet(.parameters(parameters))
    }
    self.input = input
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.name, forKey: .name)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.widgetType, forKey: .widgetType)
    try container.encode(self.uiConfig, forKey: .uiConfig)
    try container.encode(self.dataMapping, forKey: .dataMapping)
    try container.encode(self.textResponseConfig, forKey: .textResponseConfig)

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

  /// Configuration for the text response returned with the widget.
  public struct TextResponseConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The strategy for providing the text response.
    public var type: WidgetTool.TextResponseConfig.Type_ = WidgetTool.TextResponseConfig.Type_()

    /// Optional. The static text response to return when type is STATIC.
    public var staticText: Swift.String = Swift.String()

    /// Optional. Instruction for the LLM on how to generate the text response.
    /// Used as the description for the text response parameter if type is
    /// LLM_GENERATED.
    public var textResponseInstruction: Swift.String = Swift.String()

    /// Initialize a new instance of `TextResponseConfig`.
    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 = TextResponseConfig().with { $0.type = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    /// Defines how the text response is produced.
    public enum Type_: Codable, Equatable, Sendable {
      /// Unspecified type.
      case unspecified
      /// The LLM dynamically decides whether to generate a text response
      /// alongside the widget based on the conversation context.
      case `none`
      /// The LLM is explicitly required to generate a text response.
      case llmGenerated
      /// A pre-defined static text response is always used.
      case `static`
      /// 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 .`none`: return 1
        case .llmGenerated: return 2
        case .`static`: return 3
        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 "TYPE_UNSPECIFIED"
        case .`none`: return "NONE"
        case .llmGenerated: return "LLM_GENERATED"
        case .`static`: return "STATIC"
        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:Type_/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "TYPE_UNSPECIFIED": self = .unspecified
        case "NONE": self = .`none`
        case "LLM_GENERATED": self = .llmGenerated
        case "STATIC": self = .`static`
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Type_/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .`none`
        case 2: self = .llmGenerated
        case 3: self = .`static`
        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 .`none`: return try container.encode(1)
        case .llmGenerated: return try container.encode(2)
        case .`static`: return try container.encode(3)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

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

  /// Configuration for mapping data from a source tool to the widget's input
  /// parameters.
  public struct DataMapping: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The resource name of the tool that provides the data for the
    /// widget (e.g., a search tool or a custom function). Format:
    /// `projects/{project}/locations/{location}/agents/{agent}/tools/{tool}`
    public var sourceToolName: Swift.String = Swift.String()

    /// Optional. A map of widget input parameter fields to the corresponding
    /// output fields of the source tool.
    public var fieldMappings: [Swift.String: Swift.String] = [:]

    /// Optional. Configuration for a Python function used to transform the
    /// source tool's output into the widget's input format.
    public var pythonFunction: PythonFunction? = nil

    /// Optional. The mode of the data mapping.
    public var mode: WidgetTool.DataMapping.Mode = WidgetTool.DataMapping.Mode()

    /// Deprecated: Use `python_function` instead.
    @available(*, deprecated)
    public var pythonScript: Swift.String = Swift.String()

    /// Initialize a new instance of `DataMapping`.
    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 = DataMapping().with { $0.sourceToolName = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    /// The strategy used to map data from the source tool to the widget.
    public enum Mode: Codable, Equatable, Sendable {
      /// Unspecified mode.
      case unspecified
      /// Use the `field_mappings` map for data transformation.
      case fieldMapping
      /// Use the `python_script` for data transformation.
      case pythonScript
      /// 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 .fieldMapping: return 1
        case .pythonScript: return 2
        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 "MODE_UNSPECIFIED"
        case .fieldMapping: return "FIELD_MAPPING"
        case .pythonScript: return "PYTHON_SCRIPT"
        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:Mode/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "MODE_UNSPECIFIED": self = .unspecified
        case "FIELD_MAPPING": self = .fieldMapping
        case "PYTHON_SCRIPT": self = .pythonScript
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Mode/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .fieldMapping
        case 2: self = .pythonScript
        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 .fieldMapping: return try container.encode(1)
        case .pythonScript: return try container.encode(2)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

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

  /// All available widget types.
  /// New values may be added to this enum in the future.
  public enum WidgetType: Codable, Equatable, Sendable {
    /// Unspecified widget type.
    case unspecified
    /// Custom widget type.
    case custom
    /// Product carousel widget.
    case productCarousel
    /// Product details widget.
    case productDetails
    /// Quick actions widget.
    case quickActions
    /// Product comparison widget.
    case productComparison
    /// Advanced product details widget.
    case advancedProductDetails
    /// Short form widget.
    case shortForm
    /// Overall satisfaction widget.
    case overallSatisfaction
    /// Order summary widget.
    case orderSummary
    /// Appointment details widget.
    case appointmentDetails
    /// Appointment scheduler widget.
    case appointmentScheduler
    /// Contact form widget.
    case contactForm
    /// 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 .custom: return 1
      case .productCarousel: return 2
      case .productDetails: return 3
      case .quickActions: return 4
      case .productComparison: return 5
      case .advancedProductDetails: return 6
      case .shortForm: return 7
      case .overallSatisfaction: return 8
      case .orderSummary: return 9
      case .appointmentDetails: return 10
      case .appointmentScheduler: return 11
      case .contactForm: return 12
      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 "WIDGET_TYPE_UNSPECIFIED"
      case .custom: return "CUSTOM"
      case .productCarousel: return "PRODUCT_CAROUSEL"
      case .productDetails: return "PRODUCT_DETAILS"
      case .quickActions: return "QUICK_ACTIONS"
      case .productComparison: return "PRODUCT_COMPARISON"
      case .advancedProductDetails: return "ADVANCED_PRODUCT_DETAILS"
      case .shortForm: return "SHORT_FORM"
      case .overallSatisfaction: return "OVERALL_SATISFACTION"
      case .orderSummary: return "ORDER_SUMMARY"
      case .appointmentDetails: return "APPOINTMENT_DETAILS"
      case .appointmentScheduler: return "APPOINTMENT_SCHEDULER"
      case .contactForm: return "CONTACT_FORM"
      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:WidgetType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "WIDGET_TYPE_UNSPECIFIED": self = .unspecified
      case "CUSTOM": self = .custom
      case "PRODUCT_CAROUSEL": self = .productCarousel
      case "PRODUCT_DETAILS": self = .productDetails
      case "QUICK_ACTIONS": self = .quickActions
      case "PRODUCT_COMPARISON": self = .productComparison
      case "ADVANCED_PRODUCT_DETAILS": self = .advancedProductDetails
      case "SHORT_FORM": self = .shortForm
      case "OVERALL_SATISFACTION": self = .overallSatisfaction
      case "ORDER_SUMMARY": self = .orderSummary
      case "APPOINTMENT_DETAILS": self = .appointmentDetails
      case "APPOINTMENT_SCHEDULER": self = .appointmentScheduler
      case "CONTACT_FORM": self = .contactForm
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:WidgetType/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .custom
      case 2: self = .productCarousel
      case 3: self = .productDetails
      case 4: self = .quickActions
      case 5: self = .productComparison
      case 6: self = .advancedProductDetails
      case 7: self = .shortForm
      case 8: self = .overallSatisfaction
      case 9: self = .orderSummary
      case 10: self = .appointmentDetails
      case 11: self = .appointmentScheduler
      case 12: self = .contactForm
      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 .custom: return try container.encode(1)
      case .productCarousel: return try container.encode(2)
      case .productDetails: return try container.encode(3)
      case .quickActions: return try container.encode(4)
      case .productComparison: return try container.encode(5)
      case .advancedProductDetails: return try container.encode(6)
      case .shortForm: return try container.encode(7)
      case .overallSatisfaction: return try container.encode(8)
      case .orderSummary: return try container.encode(9)
      case .appointmentDetails: return try container.encode(10)
      case .appointmentScheduler: return try container.encode(11)
      case .contactForm: return try container.encode(12)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// The input of the widget tool.
  public enum OneOf_Input: Codable, Equatable, Sendable {
    /// Optional. The input parameters of the widget tool.
    indirect case parameters(Schema?)
  }

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