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

/// A toolset represents a group of dynamically managed tools that can be used
/// by the agent.
public struct Toolset: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The unique identifier of the toolset.
  /// Format:
  /// `projects/{project}/locations/{location}/apps/{app}/toolsets/{toolset}`
  public var name: Swift.String = Swift.String()

  /// Optional. The display name of the toolset. Must be unique within the same
  /// app.
  public var displayName: Swift.String = Swift.String()

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

  /// Optional. The timeout for the toolset execution. If not set, the default
  /// timeout is 30 seconds for `SYNCHRONOUS` toolsets and 60 seconds for
  /// `ASYNCHRONOUS` toolsets.
  public var timeout: GoogleCloudWkt.Duration? = nil

  /// Output only. Timestamp when the toolset was created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Timestamp when the toolset was last updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// ETag used to ensure the object hasn't changed during a read-modify-write
  /// operation. If the etag is empty, the update will overwrite any concurrent
  /// changes.
  public var etag: Swift.String = Swift.String()

  /// Optional. The execution type of the tools in the toolset.
  public var executionType: ExecutionType = ExecutionType()

  /// Optional. Configuration for tools behavior in fake mode.
  public var toolFakeConfig: ToolFakeConfig? = nil

  /// The type of the toolset.
  public var toolsetType: OneOf_ToolsetType? = nil

  /// Initialize a new instance of `Toolset`.
  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 = Toolset().with { $0.mcpToolset = ... }
  /// ```
  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 mcpToolset = "mcpToolset"
    case openApiToolset = "openApiToolset"
    case connectorToolset = "connectorToolset"
    case name = "name"
    case displayName = "displayName"
    case description = "description"
    case timeout = "timeout"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case etag = "etag"
    case executionType = "executionType"
    case toolFakeConfig = "toolFakeConfig"
  }

  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.displayName = try container.decode(Swift.String.self, forKey: .displayName)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.timeout = try container.decodeIfPresent(GoogleCloudWkt.Duration.self, forKey: .timeout)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.etag = try container.decode(Swift.String.self, forKey: .etag)
    self.executionType = try container.decode(ExecutionType.self, forKey: .executionType)
    self.toolFakeConfig = try container.decodeIfPresent(
      ToolFakeConfig.self, forKey: .toolFakeConfig)

    var toolsetType: OneOf_ToolsetType? = nil
    let toolsetTypeCheckAndSet = {
      if toolsetType != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'toolsetType'"))
      }
      toolsetType = $0
    }
    if let mcpToolset = try container.decodeIfPresent(McpToolset?.self, forKey: .mcpToolset) {
      try toolsetTypeCheckAndSet(.mcpToolset(mcpToolset))
    }
    if let openApiToolset = try container.decodeIfPresent(
      OpenApiToolset?.self, forKey: .openApiToolset)
    {
      try toolsetTypeCheckAndSet(.openApiToolset(openApiToolset))
    }
    if let connectorToolset = try container.decodeIfPresent(
      ConnectorToolset?.self, forKey: .connectorToolset)
    {
      try toolsetTypeCheckAndSet(.connectorToolset(connectorToolset))
    }
    self.toolsetType = toolsetType
  }

  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.displayName, forKey: .displayName)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.timeout, forKey: .timeout)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.etag, forKey: .etag)
    try container.encode(self.executionType, forKey: .executionType)
    try container.encode(self.toolFakeConfig, forKey: .toolFakeConfig)

    if let choice = self.toolsetType {
      switch choice {
      case .mcpToolset(let value):
        try container.encode(value, forKey: .mcpToolset)
      case .openApiToolset(let value):
        try container.encode(value, forKey: .openApiToolset)
      case .connectorToolset(let value):
        try container.encode(value, forKey: .connectorToolset)
      }
    }
  }

  /// The type of the toolset.
  public enum OneOf_ToolsetType: Codable, Equatable, Sendable {
    /// Optional. A toolset that contains a list of tools that are offered by the
    /// MCP server.
    indirect case mcpToolset(McpToolset?)
    /// Optional. A toolset that contains a list of tools that are defined by an
    /// OpenAPI schema.
    indirect case openApiToolset(OpenApiToolset?)
    /// Optional. A toolset that generates tools from an Integration Connectors
    /// Connection.
    indirect case connectorToolset(ConnectorToolset?)
  }

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