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

/// ConfigVariable represents a additional configuration variable present in a
/// PluginInstance Config or AuthConfig, based on a ConfigVariableTemplate.
public struct ConfigVariable: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. Key will be the
  /// [id][google.cloud.apihub.v1.ConfigVariableTemplate.id] to uniquely identify
  /// the config variable.
  ///
  /// [google.cloud.apihub.v1.ConfigVariableTemplate.id]: <doc:ConfigVariableTemplate/id>
  public var key: Swift.String = Swift.String()

  /// The values associated with the config variable.
  public var value: OneOf_Value? = nil

  /// Initialize a new instance of `ConfigVariable`.
  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 = ConfigVariable().with { $0.stringValue = ... }
  /// ```
  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 stringValue = "stringValue"
    case intValue = "intValue"
    case boolValue = "boolValue"
    case secretValue = "secretValue"
    case enumValue = "enumValue"
    case multiSelectValues = "multiSelectValues"
    case multiStringValues = "multiStringValues"
    case multiIntValues = "multiIntValues"
    case key = "key"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.key = try container.decode(Swift.String.self, forKey: .key)

    var value: OneOf_Value? = nil
    let valueCheckAndSet = {
      if value != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'value'"))
      }
      value = $0
    }
    if let stringValue = try container.decodeIfPresent(Swift.String.self, forKey: .stringValue) {
      try valueCheckAndSet(.stringValue(stringValue))
    }
    if let intValue = try container.decodeIfPresent(Swift.Int64.self, forKey: .intValue) {
      try valueCheckAndSet(.intValue(intValue))
    }
    if let boolValue = try container.decodeIfPresent(Swift.Bool.self, forKey: .boolValue) {
      try valueCheckAndSet(.boolValue(boolValue))
    }
    if let secretValue = try container.decodeIfPresent(Secret?.self, forKey: .secretValue) {
      try valueCheckAndSet(.secretValue(secretValue))
    }
    if let enumValue = try container.decodeIfPresent(ConfigValueOption?.self, forKey: .enumValue) {
      try valueCheckAndSet(.enumValue(enumValue))
    }
    if let multiSelectValues = try container.decodeIfPresent(
      ConfigVariable.MultiSelectValues?.self, forKey: .multiSelectValues)
    {
      try valueCheckAndSet(.multiSelectValues(multiSelectValues))
    }
    if let multiStringValues = try container.decodeIfPresent(
      ConfigVariable.MultiStringValues?.self, forKey: .multiStringValues)
    {
      try valueCheckAndSet(.multiStringValues(multiStringValues))
    }
    if let multiIntValues = try container.decodeIfPresent(
      ConfigVariable.MultiIntValues?.self, forKey: .multiIntValues)
    {
      try valueCheckAndSet(.multiIntValues(multiIntValues))
    }
    self.value = value
  }

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

    if let choice = self.value {
      switch choice {
      case .stringValue(let value):
        try container.encode(value, forKey: .stringValue)
      case .intValue(let value):
        try container.encode(value, forKey: .intValue)
      case .boolValue(let value):
        try container.encode(value, forKey: .boolValue)
      case .secretValue(let value):
        try container.encode(value, forKey: .secretValue)
      case .enumValue(let value):
        try container.encode(value, forKey: .enumValue)
      case .multiSelectValues(let value):
        try container.encode(value, forKey: .multiSelectValues)
      case .multiStringValues(let value):
        try container.encode(value, forKey: .multiStringValues)
      case .multiIntValues(let value):
        try container.encode(value, forKey: .multiIntValues)
      }
    }
  }

  /// The config variable value of data type multi select.
  public struct MultiSelectValues: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The config variable value of data type multi select.
    public var values: [ConfigValueOption] = []

    /// Initialize a new instance of `MultiSelectValues`.
    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 = MultiSelectValues().with { $0.values = ... }
    /// ```
    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.apihub.v1.ConfigVariable.MultiSelectValues"
    }
    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)
    }
  }

  /// The config variable value of data type multi string.
  public struct MultiStringValues: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The config variable value of data type multi string.
    public var values: [Swift.String] = []

    /// Initialize a new instance of `MultiStringValues`.
    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 = MultiStringValues().with { $0.values = ... }
    /// ```
    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.apihub.v1.ConfigVariable.MultiStringValues"
    }
    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)
    }
  }

  /// The config variable value of data type multi int.
  public struct MultiIntValues: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The config variable value of data type multi int.
    public var values: [Swift.Int32] = []

    /// Initialize a new instance of `MultiIntValues`.
    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 = MultiIntValues().with { $0.values = ... }
    /// ```
    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.apihub.v1.ConfigVariable.MultiIntValues"
    }
    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)
    }
  }

  /// The values associated with the config variable.
  public enum OneOf_Value: Codable, Equatable, Sendable {
    /// Optional. The config variable value in case of config variable of type
    /// string.
    case stringValue(Swift.String)
    /// Optional. The config variable value in case of config variable of type
    /// integer.
    case intValue(Swift.Int64)
    /// Optional. The config variable value in case of config variable of type
    /// boolean.
    case boolValue(Swift.Bool)
    /// Optional. The config variable value in case of config variable of type
    /// secret.
    indirect case secretValue(Secret?)
    /// Optional. The config variable value in case of config variable of type
    /// enum.
    indirect case enumValue(ConfigValueOption?)
    /// Optional. The config variable value in case of config variable of type
    /// multi select.
    indirect case multiSelectValues(ConfigVariable.MultiSelectValues?)
    /// Optional. The config variable value in case of config variable of type
    /// multi string.
    indirect case multiStringValues(ConfigVariable.MultiStringValues?)
    /// Optional. The config variable value in case of config variable of type
    /// multi integer.
    indirect case multiIntValues(ConfigVariable.MultiIntValues?)
  }

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