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

  /// The Knowledge Connector settings for this page or flow.
  /// This includes information such as the attached Knowledge Bases, and the way
  /// to execute fulfillment.
  public struct KnowledgeConnectorSettings: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Whether Knowledge Connector is enabled or not.
    public var enabled: Swift.Bool = Swift.Bool()

    /// The fulfillment to be triggered.
    ///
    /// When the answers from the Knowledge Connector are selected by Dialogflow,
    /// you can utitlize the request scoped parameter `$request.knowledge.answers`
    /// (contains up to the 5 highest confidence answers) and
    /// `$request.knowledge.questions` (contains the corresponding questions) to
    /// construct the fulfillment.
    public var triggerFulfillment: Fulfillment? = nil

    /// Optional. List of related data store connections.
    public var dataStoreConnections: [DataStoreConnection] = []

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

    /// Initialize a new instance of `KnowledgeConnectorSettings`.
    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 = KnowledgeConnectorSettings().with { $0.enabled = ... }
    /// ```
    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 enabled = "enabled"
      case triggerFulfillment = "triggerFulfillment"
      case targetPage = "targetPage"
      case targetFlow = "targetFlow"
      case dataStoreConnections = "dataStoreConnections"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.enabled = try container.decode(Swift.Bool.self, forKey: .enabled)
      self.triggerFulfillment = try container.decodeIfPresent(
        Fulfillment.self, forKey: .triggerFulfillment)
      self.dataStoreConnections = try container.decode(
        [DataStoreConnection].self, forKey: .dataStoreConnections)

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

      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
    /// [KnowledgeConnectorSettings][google.cloud.dialogflow.cx.v3.KnowledgeConnectorSettings]),
    /// or another flow in the same agent.
    ///
    /// [google.cloud.dialogflow.cx.v3.KnowledgeConnectorSettings]: <doc:KnowledgeConnectorSettings>
    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.KnowledgeConnectorSettings"
    }
    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
