// 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 Flows || Pages || Sessions || TestCases || TransitionRouteGroups
  import Foundation
  import GoogleCloudWkt

  /// A transition route specifies a [intent][google.cloud.dialogflow.cx.v3.Intent]
  /// that can be matched and/or a data condition that can be evaluated during a
  /// session. When a specified transition is matched, the following actions are
  /// taken in order:
  ///
  /// *   If there is a
  /// [`trigger_fulfillment`][google.cloud.dialogflow.cx.v3.TransitionRoute.trigger_fulfillment]
  /// associated with the transition, it will be called.
  /// *   If there is a
  /// [`target_page`][google.cloud.dialogflow.cx.v3.TransitionRoute.target_page]
  /// associated with the transition, the session will transition into the
  /// specified page.
  /// *   If there is a
  /// [`target_flow`][google.cloud.dialogflow.cx.v3.TransitionRoute.target_flow]
  /// associated with the transition, the session will transition into the
  /// specified flow.
  ///
  /// [google.cloud.dialogflow.cx.v3.Intent]: <doc:Intent>
  /// [google.cloud.dialogflow.cx.v3.TransitionRoute.target_flow]: <doc:TransitionRoute/targetFlow>
  /// [google.cloud.dialogflow.cx.v3.TransitionRoute.target_page]: <doc:TransitionRoute/targetPage>
  /// [google.cloud.dialogflow.cx.v3.TransitionRoute.trigger_fulfillment]: <doc:TransitionRoute/triggerFulfillment>
  public struct TransitionRoute: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. The unique identifier of this transition route.
    public var name: Swift.String = Swift.String()

    /// Optional. The description of the transition route. The maximum length is
    /// 500 characters.
    public var description: Swift.String = Swift.String()

    /// The unique identifier of an [Intent][google.cloud.dialogflow.cx.v3.Intent].
    /// Format:
    /// `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/intents/<IntentID>`.
    /// Indicates that the transition can only happen when the given intent is
    /// matched.
    /// At least one of `intent` or `condition` must be specified. When both
    /// `intent` and `condition` are specified, the transition can only happen
    /// when both are fulfilled.
    ///
    /// [google.cloud.dialogflow.cx.v3.Intent]: <doc:Intent>
    public var intent: Swift.String = Swift.String()

    /// The condition to evaluate against [form
    /// parameters][google.cloud.dialogflow.cx.v3.Form.parameters] or [session
    /// parameters][google.cloud.dialogflow.cx.v3.SessionInfo.parameters].
    ///
    /// See the [conditions
    /// reference](https://cloud.google.com/dialogflow/cx/docs/reference/condition).
    /// At least one of `intent` or `condition` must be specified. When both
    /// `intent` and `condition` are specified, the transition can only happen
    /// when both are fulfilled.
    ///
    /// [google.cloud.dialogflow.cx.v3.Form.parameters]: <doc:Form/parameters>
    /// [google.cloud.dialogflow.cx.v3.SessionInfo.parameters]: <doc:SessionInfo/parameters>
    public var condition: Swift.String = Swift.String()

    /// The fulfillment to call when the condition is satisfied. At least one of
    /// `trigger_fulfillment` and `target` must be specified. When both are
    /// defined, `trigger_fulfillment` is executed first.
    public var triggerFulfillment: Fulfillment? = nil

    /// The target to transition to, either a page in the same host flow (the flow
    /// that owns this
    /// [TransitionRoute][google.cloud.dialogflow.cx.v3.TransitionRoute]), or
    /// another flow in the same agent.
    ///
    /// [google.cloud.dialogflow.cx.v3.TransitionRoute]: <doc:TransitionRoute>
    public var target: OneOf_Target? = nil

    /// Initialize a new instance of `TransitionRoute`.
    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 = TransitionRoute().with { $0.name = ... }
    /// ```
    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 name = "name"
      case description = "description"
      case intent = "intent"
      case condition = "condition"
      case triggerFulfillment = "triggerFulfillment"
      case targetPage = "targetPage"
      case targetFlow = "targetFlow"
    }

    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.intent = try container.decode(Swift.String.self, forKey: .intent)
      self.condition = try container.decode(Swift.String.self, forKey: .condition)
      self.triggerFulfillment = try container.decodeIfPresent(
        Fulfillment.self, forKey: .triggerFulfillment)

      var target: OneOf_Target? = nil
      let targetCheckAndSet = {
        if target != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'target'"))
        }
        target = $0
      }
      if let targetPage = try container.decodeIfPresent(Swift.String.self, forKey: .targetPage) {
        try targetCheckAndSet(.targetPage(targetPage))
      }
      if let targetFlow = try container.decodeIfPresent(Swift.String.self, forKey: .targetFlow) {
        try targetCheckAndSet(.targetFlow(targetFlow))
      }
      self.target = target
    }

    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.intent, forKey: .intent)
      try container.encode(self.condition, forKey: .condition)
      try container.encode(self.triggerFulfillment, forKey: .triggerFulfillment)

      if let choice = self.target {
        switch choice {
        case .targetPage(let value):
          try container.encode(value, forKey: .targetPage)
        case .targetFlow(let value):
          try container.encode(value, forKey: .targetFlow)
        }
      }
    }

    /// The target to transition to, either a page in the same host flow (the flow
    /// that owns this
    /// [TransitionRoute][google.cloud.dialogflow.cx.v3.TransitionRoute]), or
    /// another flow in the same agent.
    ///
    /// [google.cloud.dialogflow.cx.v3.TransitionRoute]: <doc:TransitionRoute>
    public enum OneOf_Target: Codable, Equatable, Sendable {
      /// The target page to transition to.
      /// Format:
      /// `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/flows/<FlowID>/pages/<PageID>`.
      case targetPage(Swift.String)
      /// The target flow to transition to.
      /// Format:
      /// `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/flows/<FlowID>`.
      case targetFlow(Swift.String)
    }

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