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

  /// Playbook is the basic building block to instruct the LLM how to execute a
  /// certain task.
  ///
  /// A playbook consists of a goal to accomplish, an optional list of step by step
  /// instructions (the step instruction may refers to name of the custom or
  /// default plugin tools to use) to perform the task,
  /// a list of contextual input data to be passed in at the beginning of the
  /// invoked, and a list of output parameters to store the playbook result.
  public struct Playbook: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The unique identifier of the playbook.
    /// Format:
    /// `projects/<ProjectID>/locations/<LocationID>/agents/<AgentID>/playbooks/<PlaybookID>`.
    public var name: Swift.String = Swift.String()

    /// Required. The human-readable name of the playbook, unique within an agent.
    public var displayName: Swift.String = Swift.String()

    /// Required. High level description of the goal the playbook intend to
    /// accomplish. A goal should be concise since it's visible to other playbooks
    /// that may reference this playbook.
    public var goal: Swift.String = Swift.String()

    /// Optional. Defined structured input parameters for this playbook.
    public var inputParameterDefinitions: [ParameterDefinition] = []

    /// Optional. Defined structured output parameters for this playbook.
    public var outputParameterDefinitions: [ParameterDefinition] = []

    /// Instruction to accomplish target goal.
    public var instruction: Playbook.Instruction? = nil

    /// Output only. Estimated number of tokes current playbook takes when sent to
    /// the LLM.
    public var tokenCount: Swift.Int64 = Swift.Int64()

    /// Output only. The timestamp of initial playbook creation.
    public var createTime: GoogleCloudWkt.Timestamp? = nil

    /// Output only. Last time the playbook version was updated.
    public var updateTime: GoogleCloudWkt.Timestamp? = nil

    /// Output only. The resource name of other playbooks referenced by the current
    /// playbook in the instructions.
    public var referencedPlaybooks: [Swift.String] = []

    /// Output only. The resource name of flows referenced by the current playbook
    /// in the instructions.
    public var referencedFlows: [Swift.String] = []

    /// Optional. The resource name of tools referenced by the current playbook in
    /// the instructions. If not provided explicitly, they are will
    /// be implied using the tool being referenced in goal and steps.
    public var referencedTools: [Swift.String] = []

    /// Optional. Output only. Names of inline actions scoped to this playbook.
    /// These actions are in addition to those belonging to referenced tools, child
    /// playbooks, and flows, e.g. actions that are defined in the playbook's code
    /// block.
    public var inlineActions: [Swift.String] = []

    /// Optional. The playbook's scoped code block, which may implement handlers
    /// and actions.
    public var codeBlock: CodeBlock? = nil

    /// Optional. Llm model settings for the playbook.
    public var llmModelSettings: LlmModelSettings? = nil

    /// Optional. A list of registered handlers to execuate based on the specified
    /// triggers.
    public var handlers: [Handler] = []

    /// Optional. Type of the playbook.
    public var playbookType: Playbook.PlaybookType = Playbook.PlaybookType()

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

    /// Message of single step execution.
    public struct Step: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Sub-processing needed to execute the current step.
      public var steps: [Playbook.Step] = []

      /// Instruction on how to execute current step.
      public var instruction: OneOf_Instruction? = nil

      /// Initialize a new instance of `Step`.
      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 = Step().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 steps = "steps"
      }

      public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.steps = try container.decode([Playbook.Step].self, forKey: .steps)

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

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

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

      /// Instruction on how to execute current step.
      public enum OneOf_Instruction: Codable, Equatable, Sendable {
        /// Step instruction in text format.
        case text(Swift.String)
      }

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

    /// Message of the Instruction of the playbook.
    public struct Instruction: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// General guidelines for the playbook. These are unstructured instructions
      /// that are not directly part of the goal, e.g. "Always be polite". It's
      /// valid for this text to be long and used instead of steps altogether.
      public var guidelines: Swift.String = Swift.String()

      /// Ordered list of step by step execution instructions to accomplish
      /// target goal.
      public var steps: [Playbook.Step] = []

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

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

    /// Type of the playbook.
    public enum PlaybookType: Codable, Equatable, Sendable {
      /// Unspecified type. Default to TASK.
      case unspecified
      /// Task playbook.
      case task
      /// Routine playbook.
      case routine
      /// 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 .task: return 1
        case .routine: 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 "PLAYBOOK_TYPE_UNSPECIFIED"
        case .task: return "TASK"
        case .routine: return "ROUTINE"
        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:PlaybookType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "PLAYBOOK_TYPE_UNSPECIFIED": self = .unspecified
        case "TASK": self = .task
        case "ROUTINE": self = .routine
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:PlaybookType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .task
        case 3: self = .routine
        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 .task: return try container.encode(1)
        case .routine: 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.dialogflow.cx.v3.Playbook"
    }
    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
