// Copyright 2025 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
//
//     http://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.

syntax = "proto3";

package google.cloud.apihub.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/apihub/v1/common_fields.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.ApiHub.V1";
option go_package = "cloud.google.com/go/apihub/apiv1/apihubpb;apihubpb";
option java_multiple_files = true;
option java_outer_classname = "PluginServiceProto";
option java_package = "com.google.cloud.apihub.v1";
option php_namespace = "Google\\Cloud\\ApiHub\\V1";
option ruby_package = "Google::Cloud::ApiHub::V1";

// This service is used for managing plugins inside the API Hub.
service ApiHubPlugin {
  option (google.api.default_host) = "apihub.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Get an API Hub plugin.
  rpc GetPlugin(GetPluginRequest) returns (Plugin) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/plugins/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Enables a plugin.
  // The `state` of the plugin after enabling is `ENABLED`
  rpc EnablePlugin(EnablePluginRequest) returns (Plugin) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/plugins/*}:enable"
      body: "*"
    };
    option (google.api.method_signature) = "name";
  }

  // Disables a plugin.
  // The `state` of the plugin after disabling is `DISABLED`
  rpc DisablePlugin(DisablePluginRequest) returns (Plugin) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/plugins/*}:disable"
      body: "*"
    };
    option (google.api.method_signature) = "name";
  }

  // Create an API Hub plugin resource in the API hub.
  // Once a plugin is created, it can be used to create plugin instances.
  rpc CreatePlugin(CreatePluginRequest) returns (Plugin) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/plugins"
      body: "plugin"
    };
    option (google.api.method_signature) = "parent,plugin,plugin_id";
  }

  // List all the plugins in a given project and location.
  rpc ListPlugins(ListPluginsRequest) returns (ListPluginsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/plugins"
    };
    option (google.api.method_signature) = "parent";
  }

  // Delete a Plugin in API hub.
  // Note, only user owned plugins can be deleted via this method.
  rpc DeletePlugin(DeletePluginRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/plugins/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "OperationMetadata"
    };
  }

  // Creates a Plugin instance in the API hub.
  rpc CreatePluginInstance(CreatePluginInstanceRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/plugins/*}/instances"
      body: "plugin_instance"
    };
    option (google.api.method_signature) =
        "parent,plugin_instance,plugin_instance_id";
    option (google.longrunning.operation_info) = {
      response_type: "PluginInstance"
      metadata_type: "OperationMetadata"
    };
  }

  // Executes a plugin instance in the API hub.
  rpc ExecutePluginInstanceAction(ExecutePluginInstanceActionRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/plugins/*/instances/*}:executeAction"
      body: "*"
    };
    option (google.api.method_signature) = "name,action_execution_detail";
    option (google.longrunning.operation_info) = {
      response_type: "ExecutePluginInstanceActionResponse"
      metadata_type: "OperationMetadata"
    };
  }

  // Get an API Hub plugin instance.
  rpc GetPluginInstance(GetPluginInstanceRequest) returns (PluginInstance) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/plugins/*/instances/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // List all the plugins in a given project and location.
  // `-` can be used as wildcard value for {plugin_id}
  rpc ListPluginInstances(ListPluginInstancesRequest)
      returns (ListPluginInstancesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*/plugins/*}/instances"
    };
    option (google.api.method_signature) = "parent";
  }

  // Enables a plugin instance in the API hub.
  rpc EnablePluginInstanceAction(EnablePluginInstanceActionRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/plugins/*/instances/*}:enableAction"
      body: "*"
    };
    option (google.api.method_signature) = "name,action_id";
    option (google.longrunning.operation_info) = {
      response_type: "EnablePluginInstanceActionResponse"
      metadata_type: "OperationMetadata"
    };
  }

  // Disables a plugin instance in the API hub.
  rpc DisablePluginInstanceAction(DisablePluginInstanceActionRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/plugins/*/instances/*}:disableAction"
      body: "*"
    };
    option (google.api.method_signature) = "name,action_id";
    option (google.longrunning.operation_info) = {
      response_type: "DisablePluginInstanceActionResponse"
      metadata_type: "OperationMetadata"
    };
  }

  // Updates a plugin instance in the API hub.
  // The following fields in the
  // [plugin_instance][google.cloud.apihub.v1.PluginInstance] can be updated
  // currently:
  //
  // * [display_name][google.cloud.apihub.v1.PluginInstance.display_name]
  // * [schedule_cron_expression][PluginInstance.actions.schedule_cron_expression]
  //
  // The
  // [update_mask][google.cloud.apihub.v1.UpdatePluginInstanceRequest.update_mask]
  // should be used to specify the fields being updated.
  //
  // To update the
  // [auth_config][google.cloud.apihub.v1.PluginInstance.auth_config] and
  // [additional_config][google.cloud.apihub.v1.PluginInstance.additional_config]
  // of the plugin instance, use the
  // [ApplyPluginInstanceConfig][google.cloud.apihub.v1.ApiHubPlugin.ApplyPluginInstanceConfig]
  // method.
  rpc UpdatePluginInstance(UpdatePluginInstanceRequest)
      returns (PluginInstance) {
    option (google.api.http) = {
      patch: "/v1/{plugin_instance.name=projects/*/locations/*/plugins/*/instances/*}"
      body: "plugin_instance"
    };
    option (google.api.method_signature) = "plugin_instance,update_mask";
  }

  // Deletes a plugin instance in the API hub.
  rpc DeletePluginInstance(DeletePluginInstanceRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/plugins/*/instances/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "OperationMetadata"
    };
  }
}

// Enum for the action type.
enum ActionType {
  // Default unspecified action type.
  ACTION_TYPE_UNSPECIFIED = 0;

  // Action type for sync metadata.
  SYNC_METADATA = 1;

  // Action type for sync runtime data.
  SYNC_RUNTIME_DATA = 2;
}

// Enum for the gateway type.
enum GatewayType {
  // The gateway type is not specified.
  GATEWAY_TYPE_UNSPECIFIED = 0;

  // The gateway type is Apigee X and Hybrid.
  APIGEE_X_AND_HYBRID = 1;

  // The gateway type is Apigee Edge Public Cloud.
  APIGEE_EDGE_PUBLIC_CLOUD = 2;

  // The gateway type is Apigee Edge Private Cloud.
  APIGEE_EDGE_PRIVATE_CLOUD = 3;

  // The gateway type is Cloud API Gateway.
  CLOUD_API_GATEWAY = 4;

  // The gateway type is Cloud Endpoints.
  CLOUD_ENDPOINTS = 5;

  // The gateway type is API Discovery.
  API_DISCOVERY = 6;

  // The gateway type for any other types of gateways.
  OTHERS = 7;
}

// Enum for the curation type.
enum CurationType {
  // Default unspecified curation type.
  CURATION_TYPE_UNSPECIFIED = 0;

  // Default curation for API metadata will be used.
  DEFAULT_CURATION_FOR_API_METADATA = 1;

  // Custom curation for API metadata will be used.
  CUSTOM_CURATION_FOR_API_METADATA = 2;
}

// A plugin resource in the API Hub.
message Plugin {
  option (google.api.resource) = {
    type: "apihub.googleapis.com/Plugin"
    pattern: "projects/{project}/locations/{location}/plugins/{plugin}"
    plural: "plugins"
    singular: "plugin"
  };

  // The information related to the service implemented by the plugin
  // developer, used to invoke the plugin's functionality.
  message HostingService {
    // 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.
    string service_uri = 1 [(google.api.field_behavior) = OPTIONAL];
  }

  // ConfigTemplate represents the configuration template for a plugin.
  message ConfigTemplate {
    // AuthConfigTemplate represents the authentication template for a plugin.
    message AuthConfigTemplate {
      // Required. The list of authentication types supported by the plugin.
      repeated AuthType supported_auth_types = 1
          [(google.api.field_behavior) = REQUIRED];

      // 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.
      GoogleServiceAccountConfig service_account = 2
          [(google.api.field_behavior) = OPTIONAL];
    }

    // Optional. The authentication template for the plugin.
    AuthConfigTemplate auth_config_template = 1
        [(google.api.field_behavior) = OPTIONAL];

    // Optional. The list of additional configuration variables for the plugin's
    // configuration.
    repeated ConfigVariableTemplate additional_config_template = 2
        [(google.api.field_behavior) = OPTIONAL];
  }

  // 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.
  enum State {
    // The default value. This value is used if the state is omitted.
    STATE_UNSPECIFIED = 0;

    // The plugin is enabled.
    ENABLED = 1;

    // The plugin is disabled.
    DISABLED = 2;
  }

  // Ownership type of the plugin.
  enum OwnershipType {
    // Default unspecified type.
    OWNERSHIP_TYPE_UNSPECIFIED = 0;

    // System owned plugins are defined by API hub and are available out of the
    // box in API hub.
    SYSTEM_OWNED = 1;

    // 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.
    USER_OWNED = 2;
  }

  // Identifier. The name of the plugin.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. The display name of the plugin. Max length is 50 characters
  // (Unicode code points).
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // 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.
  AttributeValues type = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The plugin description. Max length is 2000 characters (Unicode
  // code points).
  string description = 4 [(google.api.field_behavior) = OPTIONAL];

  // 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.
  State state = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The type of the plugin, indicating whether it is
  // 'SYSTEM_OWNED' or 'USER_OWNED'.
  OwnershipType ownership_type = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // 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.
  HostingService hosting_service = 7 [(google.api.field_behavior) = OPTIONAL];

  // 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.
  repeated PluginActionConfig actions_config = 8
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The documentation of the plugin, that explains how to set up and
  // use the plugin.
  Documentation documentation = 9 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The category of the plugin, identifying its primary category or
  // purpose. This field is required for all plugins.
  PluginCategory plugin_category = 11 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The configuration template for the plugin.
  ConfigTemplate config_template = 12 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Timestamp indicating when the plugin was created.
  google.protobuf.Timestamp create_time = 13
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp indicating when the plugin was last updated.
  google.protobuf.Timestamp update_time = 14
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The type of the gateway.
  GatewayType gateway_type = 15 [(google.api.field_behavior) = OPTIONAL];
}

// PluginActionConfig represents the configuration of an action supported by a
// plugin.
message PluginActionConfig {
  // Execution mode of the action.
  enum TriggerMode {
    // Default unspecified mode.
    TRIGGER_MODE_UNSPECIFIED = 0;

    // This action can be executed by invoking
    // [ExecutePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.ExecutePluginInstanceAction]
    // API with the given action id. To support this, the plugin hosting service
    // should handle this action id as part of execute call.
    API_HUB_ON_DEMAND_TRIGGER = 1;

    // This action will be executed on schedule by invoking
    // [ExecutePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.ExecutePluginInstanceAction]
    // API with the given action id. To set the schedule, the user can provide
    // the cron expression in the
    // [PluginAction][PluginAction.schedule_cron_expression] field for a given
    // plugin instance. To support this, the plugin hosting service should
    // handle this action id as part of execute call.
    // Note, on demand execution will be supported by default in this trigger
    // mode.
    API_HUB_SCHEDULE_TRIGGER = 2;

    // The execution of this plugin is not handled by API hub. In this case,
    // the plugin hosting service need not handle this action id as part of
    // the execute call.
    NON_API_HUB_MANAGED = 3;
  }

  // Required. The id of the action.
  string id = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The display name of the action.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The description of the operation performed by the action.
  string description = 3 [(google.api.field_behavior) = REQUIRED];

  // Required. The trigger mode supported by the action.
  TriggerMode trigger_mode = 4 [(google.api.field_behavior) = REQUIRED];
}

// The [GetPlugin][google.cloud.apihub.v1.ApiHubPlugin.GetPlugin] method's
// request.
message GetPluginRequest {
  // Required. The name of the plugin to retrieve.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "apihub.googleapis.com/Plugin" }
  ];
}

// The [EnablePlugin][google.cloud.apihub.v1.ApiHubPlugin.EnablePlugin] method's
// request.
message EnablePluginRequest {
  // Required. The name of the plugin to enable.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "apihub.googleapis.com/Plugin" }
  ];
}

// The [DisablePlugin][google.cloud.apihub.v1.ApiHubPlugin.DisablePlugin]
// method's request.
message DisablePluginRequest {
  // Required. The name of the plugin to disable.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "apihub.googleapis.com/Plugin" }
  ];
}

// PluginInstanceAction represents an action which can be executed in the plugin
// instance.
message PluginInstanceAction {
  // The configuration of resources created for a given plugin instance action.
  message ResourceConfig {
    // Output only. The type of the action.
    ActionType action_type = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The pubsub topic to publish the data to. Format is
    // projects/{project}/topics/{topic}
    string pubsub_topic = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // State represents the state of the plugin instance action.
  enum State {
    // Default unspecified state.
    STATE_UNSPECIFIED = 0;

    // The action is enabled in the plugin instance i.e., executions can
    // be triggered for this action.
    ENABLED = 1;

    // The action is disabled in the plugin instance i.e., no executions
    // can be triggered for this action. This state indicates that the user
    // explicitly disabled the instance, and no further action is needed unless
    // the user wants to re-enable it.
    DISABLED = 2;

    // The action in the plugin instance is being enabled.
    ENABLING = 3;

    // The action in the plugin instance is being disabled.
    DISABLING = 4;

    // The ERROR state can come while enabling/disabling plugin instance action.
    // Users can retrigger enable, disable via
    // [EnablePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.EnablePluginInstanceAction]
    // and
    // [DisablePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.DisablePluginInstanceAction]
    // to restore the action back to enabled/disabled state. Note enable/disable
    // on actions can only be triggered if plugin instance is in Active state.
    ERROR = 5;
  }

  // The status of the plugin action.
  oneof action_status {
    // Optional. The execution information for the plugin instance action done
    // corresponding to an API hub instance.
    ExecutionStatus hub_instance_action = 6
        [(google.api.field_behavior) = OPTIONAL];
  }

  // Required. This should map to one of the [action
  // id][google.cloud.apihub.v1.PluginActionConfig.id] specified in
  // [actions_config][google.cloud.apihub.v1.Plugin.actions_config] in the
  // plugin.
  string action_id = 1 [(google.api.field_behavior) = REQUIRED];

  // Output only. The current state of the plugin action in the plugin instance.
  State state = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The schedule for this plugin instance action. This can only be
  // set if the plugin supports API_HUB_SCHEDULE_TRIGGER mode for this action.
  string schedule_cron_expression = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. This configuration should be provided if the plugin action is
  // publishing data to API hub curate layer.
  CurationConfig curation_config = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The time zone for the schedule cron expression. If not provided,
  // UTC will be used.
  string schedule_time_zone = 7 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The service account used to publish data. Note, the service
  // account will only be accepted for non GCP plugins like OPDK.
  string service_account = 8 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The configuration of resources created for a given plugin
  // instance action. Note these will be returned only in case of Non-GCP
  // plugins like OPDK.
  ResourceConfig resource_config = 9
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// 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.
message PluginInstance {
  option (google.api.resource) = {
    type: "apihub.googleapis.com/PluginInstance"
    pattern: "projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}"
    plural: "pluginInstances"
    singular: "pluginInstance"
  };

  // State represents the state of the plugin instance.
  enum State {
    // Default unspecified state.
    STATE_UNSPECIFIED = 0;

    // The plugin instance is being created.
    CREATING = 1;

    // The plugin instance is active and ready for executions. This is the only
    // state where executions can run on the plugin instance.
    ACTIVE = 2;

    // 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.
    APPLYING_CONFIG = 3;

    // 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.
    ERROR = 4;

    // The plugin instance is in a failed state. This indicates that an
    // unrecoverable error occurred during a previous operation (Create,
    // Delete).
    FAILED = 5;

    // 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.
    DELETING = 6;
  }

  // Identifier. The unique name of the plugin instance resource.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. The display name for this plugin instance. Max length is 255
  // characters.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. The authentication information for this plugin instance.
  AuthConfig auth_config = 3 [(google.api.field_behavior) = OPTIONAL];

  // 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.
  map<string, ConfigVariable> additional_config = 4
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. The current state of the plugin instance (e.g., enabled,
  // disabled, provisioning).
  State state = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // 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.
  string error_message = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. The action status for the plugin instance.
  repeated PluginInstanceAction actions = 7
      [(google.api.field_behavior) = REQUIRED];

  // Output only. Timestamp indicating when the plugin instance was created.
  google.protobuf.Timestamp create_time = 9
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp indicating when the plugin instance was last
  // updated.
  google.protobuf.Timestamp update_time = 10
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // 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.
  string source_project_id = 11 [(google.api.field_behavior) = OPTIONAL];
}

// The curation information for this plugin instance.
message CurationConfig {
  // Custom curation information for this plugin instance.
  message CustomCuration {
    // Required. The unique name of the curation resource. This will be the name
    // of the curation resource in the format:
    // `projects/{project}/locations/{location}/curations/{curation}`
    string curation = 1 [(google.api.field_behavior) = REQUIRED];
  }

  // The curation information for this plugin instance.
  oneof curation_config {
    // Optional. Custom curation information for this plugin instance.
    CustomCuration custom_curation = 2 [(google.api.field_behavior) = OPTIONAL];
  }

  // Required. The curation type for this plugin instance.
  CurationType curation_type = 1 [(google.api.field_behavior) = REQUIRED];
}

// The execution status for the plugin instance.
message ExecutionStatus {
  // The result of the last execution of the plugin instance.
  message LastExecution {
    // Enum for the result of the last execution of the plugin instance.
    enum Result {
      // Default unspecified execution result.
      RESULT_UNSPECIFIED = 0;

      // The plugin instance executed successfully.
      SUCCEEDED = 1;

      // The plugin instance execution failed.
      FAILED = 2;
    }

    // Output only. The result of the last execution of the plugin instance.
    Result result = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Error message describing the failure, if any, during the
    // last execution.
    string error_message = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The last execution start time of the plugin instance.
    google.protobuf.Timestamp start_time = 3
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The last execution end time of the plugin instance.
    google.protobuf.Timestamp end_time = 4
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Enum for the current state of the execution.
  enum CurrentExecutionState {
    // Default unspecified execution state.
    CURRENT_EXECUTION_STATE_UNSPECIFIED = 0;

    // The plugin instance is executing.
    RUNNING = 1;

    // The plugin instance is not running an execution.
    NOT_RUNNING = 2;
  }

  // Output only. The current state of the execution.
  CurrentExecutionState current_execution_state = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The last execution of the plugin instance.
  LastExecution last_execution = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The [CreatePlugin][google.cloud.apihub.v1.ApiHubPlugin.CreatePlugin] method's
// request.
message CreatePluginRequest {
  // Required. The parent resource where this plugin will be created.
  // Format: `projects/{project}/locations/{location}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "apihub.googleapis.com/Plugin"
    }
  ];

  // Optional. The ID to use for the Plugin resource, which will become the
  // final component of the Plugin's resource name. This field is optional.
  //
  // * If provided, the same will be used. The service will throw an error if
  // the specified id is already used by another Plugin resource in the API hub
  // instance.
  // * If not provided, a system generated id will be used.
  //
  // This value should be 4-63 characters, overall resource name which will be
  // of format
  // `projects/{project}/locations/{location}/plugins/{plugin}`,
  // its length is limited to 1000 characters and valid characters are
  // /[a-z][A-Z][0-9]-_/.
  string plugin_id = 2 [(google.api.field_behavior) = OPTIONAL];

  // Required. The plugin to create.
  Plugin plugin = 3 [(google.api.field_behavior) = REQUIRED];
}

// The [DeletePlugin][ApiHub.DeletePlugin] method's request.
message DeletePluginRequest {
  // Required. The name of the Plugin resource to delete.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "apihub.googleapis.com/Plugin" }
  ];
}

// The [ListPlugins][google.cloud.apihub.v1.ApiHubPlugin.ListPlugins] method's
// request.
message ListPluginsRequest {
  // Required. The parent resource where this plugin will be created.
  // Format: `projects/{project}/locations/{location}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "apihub.googleapis.com/Plugin"
    }
  ];

  // Optional. An expression that filters the list of plugins.
  //
  // A filter expression consists of a field name, a comparison
  // operator, and a value for filtering. The value must be a string. The
  // comparison operator must be one of: `<`, `>` or
  // `=`. Filters are not case sensitive.
  //
  // The following fields in the `Plugins` are eligible for filtering:
  //
  //   * `plugin_category` - The category of the Plugin. Allowed
  //   comparison operators: `=`.
  //
  // Expressions are combined with either `AND` logic operator or `OR` logical
  // operator but not both of them together i.e. only one of the `AND` or `OR`
  // operator can be used throughout the filter string and both the operators
  // cannot be used together. No other logical operators are
  // supported. At most three filter fields are allowed in the filter
  // string and if provided more than that then `INVALID_ARGUMENT` error is
  // returned by the API.
  // Here are a few examples:
  //
  //   * `plugin_category = ON_RAMP` - The plugin is of category
  //   on ramp.
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum number of hub plugins to return. The service may
  // return fewer than this value. If unspecified, at most 50 hub plugins will
  // be returned. The maximum value is 1000; values above 1000 will be coerced
  // to 1000.
  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `ListPlugins` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters (except page_size) provided to
  // `ListPlugins` must match the call that provided the page token.
  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];
}

// The [ListPlugins][google.cloud.apihub.v1.ApiHubPlugin.ListPlugins] method's
// response.
message ListPluginsResponse {
  // The plugins from the specified parent resource.
  repeated Plugin plugins = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// The
// [CreatePluginInstance][google.cloud.apihub.v1.ApiHubPlugin.CreatePluginInstance]
// method's request.
message CreatePluginInstanceRequest {
  // Required. The parent of the plugin instance resource.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "apihub.googleapis.com/Plugin" }
  ];

  // Optional. The ID to use for the plugin instance, which will become the
  // final component of the plugin instance's resource name. This field is
  // optional.
  //
  // * If provided, the same will be used. The service will throw an error if
  // the specified id is already used by another plugin instance in the plugin
  // resource.
  // * If not provided, a system generated id will be used.
  //
  // This value should be 4-63 characters, and valid characters
  // are /[a-z][A-Z][0-9]-_/.
  string plugin_instance_id = 2 [(google.api.field_behavior) = OPTIONAL];

  // Required. The plugin instance to create.
  PluginInstance plugin_instance = 3 [(google.api.field_behavior) = REQUIRED];
}

// The
// [ExecutePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.ExecutePluginInstanceAction]
// method's request.
message ExecutePluginInstanceActionRequest {
  // Required. The name of the plugin instance to execute.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "apihub.googleapis.com/PluginInstance"
    }
  ];

  // Required. The execution details for the action to execute.
  ActionExecutionDetail action_execution_detail = 2
      [(google.api.field_behavior) = REQUIRED];
}

// The details for the action to execute.
message ActionExecutionDetail {
  // Required. The action id of the plugin to execute.
  string action_id = 1 [(google.api.field_behavior) = REQUIRED];
}

// The
// [ExecutePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.ExecutePluginInstanceAction]
// method's response.
message ExecutePluginInstanceActionResponse {}

// The
// [GetPluginInstance][google.cloud.apihub.v1.ApiHubPlugin.GetPluginInstance]
// method's request.
message GetPluginInstanceRequest {
  // Required. The name of the plugin instance to retrieve.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "apihub.googleapis.com/PluginInstance"
    }
  ];
}

// The
// [ListPluginInstances][google.cloud.apihub.v1.ApiHubPlugin.ListPluginInstances]
// method's request.
message ListPluginInstancesRequest {
  // Required. The parent resource where this plugin will be created.
  // Format: `projects/{project}/locations/{location}/plugins/{plugin}`.
  // To list plugin instances for multiple plugins,
  // use the - character instead of the plugin ID.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "apihub.googleapis.com/PluginInstance"
    }
  ];

  // Optional. An expression that filters the list of plugin instances.
  //
  // A filter expression consists of a field name, a comparison
  // operator, and a value for filtering. The value must be a string. The
  // comparison operator must be one of: `<`, `>` or
  // `=`. Filters are not case sensitive.
  //
  // The following fields in the `PluginInstances` are eligible for filtering:
  //
  //   * `state` - The state of the Plugin Instance. Allowed
  //   comparison operators: `=`.
  //
  // A filter function is also supported in the filter string. The filter
  // function is `id(name)`. The `id(name)` function returns the id of the
  // resource name. For example, `id(name) = \"plugin-instance-1\"` is
  // equivalent to `name =
  // \"projects/test-project-id/locations/test-location-id/plugins/plugin-1/instances/plugin-instance-1\"`
  // provided the parent is
  // `projects/test-project-id/locations/test-location-id/plugins/plugin-1`.
  //
  // Expressions are combined with either `AND` logic operator or `OR` logical
  // operator but not both of them together i.e. only one of the `AND` or `OR`
  // operator can be used throughout the filter string and both the operators
  // cannot be used together. No other logical operators are
  // supported. At most three filter fields are allowed in the filter
  // string and if provided more than that then `INVALID_ARGUMENT` error is
  // returned by the API.
  // Here are a few examples:
  //
  //   * `state = ENABLED` - The plugin instance is in enabled state.
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The maximum number of hub plugins to return. The service may
  // return fewer than this value. If unspecified, at most 50 hub plugins will
  // be returned. The maximum value is 1000; values above 1000 will be coerced
  // to 1000.
  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `ListPluginInstances`
  // call. Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListPluginInstances`
  // must match the call that provided the page token.
  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];
}

// The
// [ListPluginInstances][google.cloud.apihub.v1.ApiHubPlugin.ListPluginInstances]
// method's response.
message ListPluginInstancesResponse {
  // The plugin instances from the specified parent resource.
  repeated PluginInstance plugin_instances = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// The
// [EnablePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.EnablePluginInstanceAction]
// method's request.
message EnablePluginInstanceActionRequest {
  // Required. The name of the plugin instance to enable.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "apihub.googleapis.com/PluginInstance"
    }
  ];

  // Required. The action id to enable.
  string action_id = 2 [(google.api.field_behavior) = REQUIRED];
}

// The
// [EnablePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.EnablePluginInstanceAction]
// method's response.
message EnablePluginInstanceActionResponse {}

// The
// [DisablePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.DisablePluginInstanceAction]
// method's request.
message DisablePluginInstanceActionRequest {
  // Required. The name of the plugin instance to disable.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "apihub.googleapis.com/PluginInstance"
    }
  ];

  // Required. The action id to disable.
  string action_id = 2 [(google.api.field_behavior) = REQUIRED];
}

// The
// [DisablePluginInstanceAction][google.cloud.apihub.v1.ApiHubPlugin.DisablePluginInstanceAction]
// method's response.
message DisablePluginInstanceActionResponse {}

// The
// [UpdatePluginInstance][google.cloud.apihub.v1.ApiHubPlugin.UpdatePluginInstance]
// method's request.
message UpdatePluginInstanceRequest {
  // Required. The plugin instance to update.
  PluginInstance plugin_instance = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The list of fields to update.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = OPTIONAL];
}

// The
// [DeletePluginInstance][google.cloud.apihub.v1.ApiHubPlugin.DeletePluginInstance]
// method's request.
message DeletePluginInstanceRequest {
  // Required. The name of the plugin instance to delete.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "apihub.googleapis.com/PluginInstance"
    }
  ];
}
