// 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 plugin resource in the API Hub.
public struct Plugin: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The name of the plugin.
  /// Format: `projects/{project}/locations/{location}/plugins/{plugin}`
  public var name: Swift.String = Swift.String()

  /// Required. The display name of the plugin. Max length is 50 characters
  /// (Unicode code points).
  public var displayName: Swift.String = Swift.String()

  /// Optional. The type of the API.
  /// This maps to the following system defined attribute:
  /// `projects/{project}/locations/{location}/attributes/system-plugin-type`
  /// attribute.
  /// The number of allowed values for this attribute will be based on the
  /// cardinality of the attribute. The same can be retrieved via GetAttribute
  /// API. All values should be from the list of allowed values defined for the
  /// attribute.
  /// Note this field is not required for plugins developed via plugin framework.
  public var type: AttributeValues? = nil

  /// Optional. The plugin description. Max length is 2000 characters (Unicode
  /// code points).
  public var description: Swift.String = Swift.String()

  /// Output only. Represents the state of the plugin.
  /// Note this field will not be set for plugins developed via plugin
  /// framework as the state will be managed at plugin instance level.
  public var state: Plugin.State = Plugin.State()

  /// Output only. The type of the plugin, indicating whether it is
  /// 'SYSTEM_OWNED' or 'USER_OWNED'.
  public var ownershipType: Plugin.OwnershipType = Plugin.OwnershipType()

  /// Optional. This field is optional. It is used to notify the plugin hosting
  /// service for any lifecycle changes of the plugin instance and trigger
  /// execution of plugin instance actions in case of API hub managed actions.
  ///
  /// This field should be provided if the plugin instance lifecycle of the
  /// developed plugin needs to be managed from API hub. Also, in this case the
  /// plugin hosting service interface needs to be implemented.
  ///
  /// This field should not be provided if the plugin wants to manage plugin
  /// instance lifecycle events outside of hub interface and use plugin framework
  /// for only registering of plugin and plugin instances to capture the source
  /// of data into hub. Note, in this case the plugin hosting service interface
  /// is not required to be implemented. Also, the plugin instance lifecycle
  /// actions will be disabled from API hub's UI.
  public var hostingService: Plugin.HostingService? = nil

  /// Optional. The configuration of actions supported by the plugin.
  /// **REQUIRED**: This field must be provided when creating or updating a
  /// Plugin. The server will reject requests if this field is missing.
  public var actionsConfig: [PluginActionConfig] = []

  /// Optional. The documentation of the plugin, that explains how to set up and
  /// use the plugin.
  public var documentation: Documentation? = nil

  /// Optional. The category of the plugin, identifying its primary category or
  /// purpose. This field is required for all plugins.
  public var pluginCategory: PluginCategory = PluginCategory()

  /// Optional. The configuration template for the plugin.
  public var configTemplate: Plugin.ConfigTemplate? = nil

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

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

  /// Optional. The type of the gateway.
  public var gatewayType: GatewayType = GatewayType()

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

  /// The information related to the service implemented by the plugin
  /// developer, used to invoke the plugin's functionality.
  public struct HostingService: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The URI of the service implemented by the plugin developer,
    /// used to invoke the plugin's functionality. This information is only
    /// required for user defined plugins.
    public var serviceUri: Swift.String = Swift.String()

    /// Initialize a new instance of `HostingService`.
    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 = HostingService().with { $0.serviceUri = ... }
    /// ```
    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.Plugin.HostingService"
    }
    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)
    }
  }

  /// ConfigTemplate represents the configuration template for a plugin.
  public struct ConfigTemplate: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The authentication template for the plugin.
    public var authConfigTemplate: Plugin.ConfigTemplate.AuthConfigTemplate? = nil

    /// Optional. The list of additional configuration variables for the plugin's
    /// configuration.
    public var additionalConfigTemplate: [ConfigVariableTemplate] = []

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

    /// AuthConfigTemplate represents the authentication template for a plugin.
    public struct AuthConfigTemplate: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. The list of authentication types supported by the plugin.
      public var supportedAuthTypes: [AuthType] = []

      /// Optional. The service account of the plugin hosting service.
      /// This service account should be granted the required permissions on the
      /// Auth Config parameters provided while creating the plugin instances
      /// corresponding to this plugin.
      ///
      /// For example, if the plugin instance auth config requires a secret
      /// manager secret, the service account should be granted the
      /// secretmanager.versions.access permission on the corresponding secret,
      /// if the plugin instance auth config contains a service account, the
      /// service account should be granted the
      /// iam.serviceAccounts.getAccessToken permission on the corresponding
      /// service account.
      public var serviceAccount: GoogleServiceAccountConfig? = nil

      /// Initialize a new instance of `AuthConfigTemplate`.
      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 = AuthConfigTemplate().with { $0.supportedAuthTypes = ... }
      /// ```
      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.Plugin.ConfigTemplate.AuthConfigTemplate"
      }
      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)
      }
    }

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

  /// Possible states a plugin can have. Note that this enum may receive new
  /// values in the future. Consumers are advised to always code against the
  /// enum values expecting new states can be added later on.
  public enum State: Codable, Equatable, Sendable {
    /// The default value. This value is used if the state is omitted.
    case unspecified
    /// The plugin is enabled.
    case enabled
    /// The plugin is disabled.
    case disabled
    /// 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 .enabled: return 1
      case .disabled: return 2
      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 .enabled: return "ENABLED"
      case .disabled: return "DISABLED"
      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 "ENABLED": self = .enabled
      case "DISABLED": self = .disabled
      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 = .enabled
      case 2: self = .disabled
      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 .enabled: return try container.encode(1)
      case .disabled: return try container.encode(2)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// Ownership type of the plugin.
  public enum OwnershipType: Codable, Equatable, Sendable {
    /// Default unspecified type.
    case unspecified
    /// System owned plugins are defined by API hub and are available out of the
    /// box in API hub.
    case systemOwned
    /// User owned plugins are defined by the user and need to be explicitly
    /// added to API hub via
    /// [CreatePlugin][google.cloud.apihub.v1.ApiHubPlugin.CreatePlugin] method.
    ///
    /// [google.cloud.apihub.v1.ApiHubPlugin.CreatePlugin]: <doc:ApiHubPlugin/createPlugin(request:)>
    case userOwned
    /// 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 .systemOwned: return 1
      case .userOwned: return 2
      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 "OWNERSHIP_TYPE_UNSPECIFIED"
      case .systemOwned: return "SYSTEM_OWNED"
      case .userOwned: return "USER_OWNED"
      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:OwnershipType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "OWNERSHIP_TYPE_UNSPECIFIED": self = .unspecified
      case "SYSTEM_OWNED": self = .systemOwned
      case "USER_OWNED": self = .userOwned
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:OwnershipType/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .systemOwned
      case 2: self = .userOwned
      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 .systemOwned: return try container.encode(1)
      case .userOwned: return try container.encode(2)
      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.Plugin"
  }
  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)
  }
}
