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

/// Represents a plugin instance resource in the API Hub.
/// A PluginInstance is a specific instance of a hub plugin with its own
/// configuration, state, and execution details.
public struct PluginInstance: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The unique name of the plugin instance resource.
  /// Format:
  /// `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`
  public var name: Swift.String = Swift.String()

  /// Required. The display name for this plugin instance. Max length is 255
  /// characters.
  public var displayName: Swift.String = Swift.String()

  /// Optional. The authentication information for this plugin instance.
  public var authConfig: AuthConfig? = nil

  /// Optional. The additional information for this plugin instance corresponding
  /// to the additional config template of the plugin. This information will be
  /// sent to plugin hosting service on each call to plugin hosted service. The
  /// key will be the config_variable_template.display_name to uniquely identify
  /// the config variable.
  public var additionalConfig: [Swift.String: ConfigVariable] = [:]

  /// Output only. The current state of the plugin instance (e.g., enabled,
  /// disabled, provisioning).
  public var state: PluginInstance.State = PluginInstance.State()

  /// Output only. Error message describing the failure, if any, during Create,
  /// Delete or ApplyConfig operation corresponding to the plugin instance.This
  /// field will only be populated if the plugin instance is in the ERROR or
  /// FAILED state.
  public var errorMessage: Swift.String = Swift.String()

  /// Required. The action status for the plugin instance.
  public var actions: [PluginInstanceAction] = []

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

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

  /// Optional. The source project id of the plugin instance. This will be the id
  /// of runtime project in case of gcp based plugins and org id in case of non
  /// gcp based plugins. This field will be a required field for Google provided
  /// on-ramp plugins.
  public var sourceProjectId: Swift.String = Swift.String()

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

  /// State represents the state of the plugin instance.
  public enum State: Codable, Equatable, Sendable {
    /// Default unspecified state.
    case unspecified
    /// The plugin instance is being created.
    case creating
    /// The plugin instance is active and ready for executions. This is the only
    /// state where executions can run on the plugin instance.
    case active
    /// The updated config that contains
    /// [additional_config][google.cloud.apihub.v1.PluginInstance.additional_config]
    /// and [auth_config][google.cloud.apihub.v1.PluginInstance.auth_config] is
    /// being applied.
    ///
    /// [google.cloud.apihub.v1.PluginInstance.additional_config]: <doc:PluginInstance/additionalConfig>
    /// [google.cloud.apihub.v1.PluginInstance.auth_config]: <doc:PluginInstance/authConfig>
    case applyingConfig
    /// The ERROR state can come while applying config. Users
    /// can retrigger
    /// [ApplyPluginInstanceConfig][google.cloud.apihub.v1.ApiHubPlugin.ApplyPluginInstanceConfig]
    /// to restore the plugin instance back to active state. Note, In case the
    /// ERROR state happens while applying config (auth_config,
    /// additional_config), the plugin instance will reflect the config which was
    /// trying to be applied while error happened. In order to overwrite, trigger
    /// ApplyConfig with a new config.
    case error
    /// The plugin instance is in a failed state. This indicates that an
    /// unrecoverable error occurred during a previous operation (Create,
    /// Delete).
    case failed
    /// The plugin instance is being deleted. Delete is only possible if there is
    /// no other operation running on the plugin instance and plugin instance
    /// action.
    case deleting
    /// 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 .creating: return 1
      case .active: return 2
      case .applyingConfig: return 3
      case .error: return 4
      case .failed: return 5
      case .deleting: return 6
      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 "STATE_UNSPECIFIED"
      case .creating: return "CREATING"
      case .active: return "ACTIVE"
      case .applyingConfig: return "APPLYING_CONFIG"
      case .error: return "ERROR"
      case .failed: return "FAILED"
      case .deleting: return "DELETING"
      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:State/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "STATE_UNSPECIFIED": self = .unspecified
      case "CREATING": self = .creating
      case "ACTIVE": self = .active
      case "APPLYING_CONFIG": self = .applyingConfig
      case "ERROR": self = .error
      case "FAILED": self = .failed
      case "DELETING": self = .deleting
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .creating
      case 2: self = .active
      case 3: self = .applyingConfig
      case 4: self = .error
      case 5: self = .failed
      case 6: self = .deleting
      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 .creating: return try container.encode(1)
      case .active: return try container.encode(2)
      case .applyingConfig: return try container.encode(3)
      case .error: return try container.encode(4)
      case .failed: return try container.encode(5)
      case .deleting: return try container.encode(6)
      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.apihub.v1.PluginInstance"
  }
  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)
  }
}
