// 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.networkservices.v1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.NetworkServices.V1";
option go_package = "cloud.google.com/go/networkservices/apiv1/networkservicespb;networkservicespb";
option java_multiple_files = true;
option java_outer_classname = "ExtensibilityProto";
option java_package = "com.google.cloud.networkservices.v1";
option php_namespace = "Google\\Cloud\\NetworkServices\\V1";
option ruby_package = "Google::Cloud::NetworkServices::V1";

// Determines the information that should be returned by the server.
enum WasmPluginView {
  // Unspecified value. Do not use.
  WASM_PLUGIN_VIEW_UNSPECIFIED = 0;

  // If specified in the `GET` request for a `WasmPlugin` resource, the server's
  // response includes just the `WasmPlugin` resource.
  WASM_PLUGIN_VIEW_BASIC = 1;

  // If specified in the `GET` request for a `WasmPlugin` resource, the server's
  // response includes the `WasmPlugin` resource with all its versions.
  WASM_PLUGIN_VIEW_FULL = 2;
}

// `WasmPlugin` is a resource representing a service executing
// a customer-provided Wasm module.
message WasmPlugin {
  option (google.api.resource) = {
    type: "networkservices.googleapis.com/WasmPlugin"
    pattern: "projects/{project}/locations/{location}/wasmPlugins/{wasm_plugin}"
  };

  // Details of a `WasmPluginVersion` resource to be inlined in the
  // `WasmPlugin` resource.
  message VersionDetails {
    oneof plugin_config_source {
      // Configuration for the plugin.
      // The configuration is provided to the plugin at runtime through
      // the `ON_CONFIGURE` callback. When a new
      // `WasmPluginVersion` version is created, the digest of the
      // contents is saved in the `plugin_config_digest` field.
      bytes plugin_config_data = 9;

      // URI of the plugin configuration stored in the Artifact Registry.
      // The configuration is provided to the plugin at runtime through
      // the `ON_CONFIGURE` callback. The container image must
      // contain only a single file with the name
      // `plugin.config`. When a new `WasmPluginVersion`
      // resource is created, the digest of the container image is saved in the
      // `plugin_config_digest` field.
      string plugin_config_uri = 10;
    }

    // Output only. The timestamp when the resource was created.
    google.protobuf.Timestamp create_time = 1
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The timestamp when the resource was updated.
    google.protobuf.Timestamp update_time = 2
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Optional. A human-readable description of the resource.
    string description = 3 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Set of labels associated with the `WasmPluginVersion`
    // resource.
    map<string, string> labels = 4 [(google.api.field_behavior) = OPTIONAL];

    // Optional. URI of the container image containing the Wasm module, stored
    // in the Artifact Registry. The container image must contain only a single
    // file with the name `plugin.wasm`. When a new `WasmPluginVersion` resource
    // is created, the URI gets resolved to an image digest and saved in the
    // `image_digest` field.
    string image_uri = 5 [(google.api.field_behavior) = OPTIONAL];

    // Output only. The resolved digest for the image specified in `image`.
    // The digest is resolved during the creation of a
    // `WasmPluginVersion` resource.
    // This field holds the digest value regardless of whether a tag or
    // digest was originally specified in the `image` field.
    string image_digest = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. This field holds the digest (usually checksum) value for the
    // plugin configuration. The value is calculated based on the contents of
    // the `plugin_config_data` field or the container image defined by the
    // `plugin_config_uri` field.
    string plugin_config_digest = 11
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Specifies the logging options for the activity performed by this
  // plugin. If logging is enabled, plugin logs are exported to
  // Cloud Logging.
  message LogConfig {
    // Possible values to specify the lowest level of logs to be exported to
    // Cloud Logging.
    enum LogLevel {
      // Unspecified value. Defaults to `LogLevel.INFO`.
      LOG_LEVEL_UNSPECIFIED = 0;

      // Report logs with TRACE level and above.
      TRACE = 1;

      // Report logs with DEBUG level and above.
      DEBUG = 2;

      // Report logs with INFO level and above.
      INFO = 3;

      // Report logs with WARN level and above.
      WARN = 4;

      // Report logs with ERROR level and above.
      ERROR = 5;

      // Report logs with CRITICAL level only.
      CRITICAL = 6;
    }

    // Optional. Specifies whether to enable logging for activity by this
    // plugin.
    //
    // Defaults to `false`.
    bool enable = 1 [(google.api.field_behavior) = OPTIONAL];

    // Non-empty default. Configures the sampling rate of activity logs, where
    // `1.0` means all logged activity is reported and `0.0` means no activity
    // is reported. A floating point value between `0.0` and `1.0` indicates
    // that a percentage of log messages is stored.
    //
    // The default value when logging is enabled is `1.0`. The value of the
    // field must be between `0` and `1` (inclusive).
    //
    // This field can be specified only if logging is enabled for this plugin.
    float sample_rate = 2 [(google.api.field_behavior) = NON_EMPTY_DEFAULT];

    // Non-empty default. Specificies the lowest level of the plugin logs that
    // are exported to Cloud Logging. This setting relates to the logs generated
    // by using logging statements in your Wasm code.
    //
    // This field is can be set only if logging is enabled for the plugin.
    //
    // If the field is not provided when logging is enabled, it is set to
    // `INFO` by default.
    LogLevel min_log_level = 3
        [(google.api.field_behavior) = NON_EMPTY_DEFAULT];
  }

  // Defines a resource that uses the `WasmPlugin` resource.
  message UsedBy {
    // Output only. Full name of the resource
    // https://google.aip.dev/122#full-resource-names, for example
    // `//networkservices.googleapis.com/projects/{project}/locations/{location}/lbRouteExtensions/{extension}`
    string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Identifier. Name of the `WasmPlugin` resource in the following format:
  // `projects/{project}/locations/{location}/wasmPlugins/{wasm_plugin}`.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The timestamp when the resource was created.
  google.protobuf.Timestamp create_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The timestamp when the resource was updated.
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. A human-readable description of the resource.
  string description = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Set of labels associated with the `WasmPlugin` resource.
  //
  // The format must comply with [the following
  // requirements](/compute/docs/labeling-resources#requirements).
  map<string, string> labels = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The ID of the `WasmPluginVersion` resource that is the
  // currently serving one. The version referred to must be a child of this
  // `WasmPlugin` resource.
  string main_version_id = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Specifies the logging options for the activity performed by this
  // plugin. If logging is enabled, plugin logs are exported to
  // Cloud Logging.
  // Note that the settings relate to the logs generated by using
  // logging statements in your Wasm code.
  LogConfig log_config = 9 [(google.api.field_behavior) = OPTIONAL];

  // Optional. All versions of this `WasmPlugin` resource in the key-value
  // format. The key is the resource ID, and the value is the `VersionDetails`
  // object.
  //
  // Lets you create or update a `WasmPlugin` resource and its versions in a
  // single request. When the `main_version_id` field is not empty, it must
  // point to one of the `VersionDetails` objects in the map.
  //
  // If provided in a `PATCH` request, the new versions replace the
  // previous set. Any version omitted from the `versions` field is removed.
  // Because the `WasmPluginVersion` resource is immutable, if a
  // `WasmPluginVersion` resource with the same name already exists and differs,
  // the request fails.
  //
  // Note: In a `GET` request, this field is populated only if the field
  // `GetWasmPluginRequest.view` is set to `WASM_PLUGIN_VIEW_FULL`.
  map<string, VersionDetails> versions = 10
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. List of all
  // [extensions](https://cloud.google.com/service-extensions/docs/overview)
  // that use this `WasmPlugin` resource.
  repeated UsedBy used_by = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// A single immutable version of a `WasmPlugin` resource.
// Defines the Wasm module used and optionally its runtime config.
message WasmPluginVersion {
  option (google.api.resource) = {
    type: "networkservices.googleapis.com/WasmPluginVersion"
    pattern: "projects/{project}/locations/{location}/wasmPlugins/{wasm_plugin}/versions/{wasm_plugin_version}"
  };

  oneof plugin_config_source {
    // Configuration for the plugin.
    // The configuration is provided to the plugin at runtime through
    // the `ON_CONFIGURE` callback. When a new
    // `WasmPluginVersion` resource is created, the digest of the
    // contents is saved in the `plugin_config_digest` field.
    bytes plugin_config_data = 12;

    // URI of the plugin configuration stored in the Artifact Registry.
    // The configuration is provided to the plugin at runtime through
    // the `ON_CONFIGURE` callback. The container image must contain
    // only a single file with the name `plugin.config`. When a
    // new `WasmPluginVersion` resource is created, the digest of the
    // container image is saved in the `plugin_config_digest` field.
    string plugin_config_uri = 13;
  }

  // Identifier. Name of the `WasmPluginVersion` resource in the following
  // format: `projects/{project}/locations/{location}/wasmPlugins/{wasm_plugin}/
  // versions/{wasm_plugin_version}`.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The timestamp when the resource was created.
  google.protobuf.Timestamp create_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The timestamp when the resource was updated.
  google.protobuf.Timestamp update_time = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. A human-readable description of the resource.
  string description = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Set of labels associated with the `WasmPluginVersion`
  // resource.
  map<string, string> labels = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. URI of the container image containing the plugin, stored in the
  // Artifact Registry.
  // When a new `WasmPluginVersion` resource is created, the digest
  // of the container image is saved in the `image_digest` field.
  // When downloading an image, the digest value is used instead of an
  // image tag.
  string image_uri = 8 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The resolved digest for the image specified in the `image`
  // field. The digest is resolved during the creation of `WasmPluginVersion`
  // resource. This field holds the digest value, regardless of whether a tag or
  // digest was originally specified in the `image` field.
  string image_digest = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. This field holds the digest (usually checksum) value for the
  // plugin configuration. The value is calculated based on the contents of
  // `plugin_config_data` or the container image defined by
  // the `plugin_config_uri` field.
  string plugin_config_digest = 14 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request used with the `ListWasmPlugins` method.
message ListWasmPluginsRequest {
  // Required. The project and location from which the `WasmPlugin` resources
  // are listed, specified in the following format:
  // `projects/{project}/locations/global`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "networkservices.googleapis.com/WasmPlugin"
    }
  ];

  // Maximum number of `WasmPlugin` resources to return per call.
  // If not specified, at most 50 `WasmPlugin` resources are returned.
  // The maximum value is 1000; values above 1000 are coerced to 1000.
  int32 page_size = 2;

  // The value returned by the last `ListWasmPluginsResponse` call.
  // Indicates that this is a continuation of a prior
  // `ListWasmPlugins` call, and that the
  // next page of data is to be returned.
  string page_token = 3;
}

// Response returned by the `ListWasmPlugins` method.
message ListWasmPluginsResponse {
  // List of `WasmPlugin` resources.
  repeated WasmPlugin wasm_plugins = 1;

  // If there might be more results than those appearing in this response, then
  // `next_page_token` is included. To get the next set of results,
  // call this method again using the value of `next_page_token` as
  // `page_token`.
  string next_page_token = 2;

  // Unreachable resources. Populated when the request attempts to list all
  // resources across all supported locations, while some locations are
  // temporarily unavailable.
  repeated string unreachable = 3;
}

// Request used by the `GetWasmPlugin` method.
message GetWasmPluginRequest {
  // Required. A name of the `WasmPlugin` resource to get. Must be in the
  // format `projects/{project}/locations/global/wasmPlugins/{wasm_plugin}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "networkservices.googleapis.com/WasmPlugin"
    }
  ];

  // Determines how much data must be returned in the response. See
  // [AIP-157](https://google.aip.dev/157).
  WasmPluginView view = 2;
}

// Request used by the `CreateWasmPlugin` method.
message CreateWasmPluginRequest {
  // Required. The parent resource of the `WasmPlugin` resource. Must be in the
  // format `projects/{project}/locations/global`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "networkservices.googleapis.com/WasmPlugin"
    }
  ];

  // Required. User-provided ID of the `WasmPlugin` resource to be created.
  string wasm_plugin_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. `WasmPlugin` resource to be created.
  WasmPlugin wasm_plugin = 3 [(google.api.field_behavior) = REQUIRED];
}

// Request used by the `UpdateWasmPlugin` method.
message UpdateWasmPluginRequest {
  // Optional. Used to specify the fields to be overwritten in the
  // `WasmPlugin` resource by the update.
  // The fields specified in the `update_mask` field are relative to the
  // resource, not the full request.
  // An omitted `update_mask` field is treated as an implied `update_mask`
  // field equivalent to all fields that are populated (that have a non-empty
  // value).
  // The `update_mask` field supports a special value `*`, which means that
  // each field in the given `WasmPlugin` resource (including the empty ones)
  // replaces the current value.
  google.protobuf.FieldMask update_mask = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Required. Updated `WasmPlugin` resource.
  WasmPlugin wasm_plugin = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request used by the `DeleteWasmPlugin` method.
message DeleteWasmPluginRequest {
  // Required. A name of the `WasmPlugin` resource to delete. Must be in the
  // format `projects/{project}/locations/global/wasmPlugins/{wasm_plugin}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "networkservices.googleapis.com/WasmPlugin"
    }
  ];
}

// Request used with the `ListWasmPluginVersions` method.
message ListWasmPluginVersionsRequest {
  // Required. The `WasmPlugin` resource whose `WasmPluginVersion`s
  // are listed, specified in the following format:
  // `projects/{project}/locations/global/wasmPlugins/{wasm_plugin}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "networkservices.googleapis.com/WasmPluginVersion"
    }
  ];

  // Maximum number of `WasmPluginVersion` resources to return per
  // call. If not specified, at most 50 `WasmPluginVersion` resources are
  // returned. The maximum value is 1000; values above 1000 are coerced to
  // 1000.
  int32 page_size = 2;

  // The value returned by the last `ListWasmPluginVersionsResponse` call.
  // Indicates that this is a continuation of a prior
  // `ListWasmPluginVersions` call, and that the
  // next page of data is to be returned.
  string page_token = 3;
}

// Response returned by the `ListWasmPluginVersions` method.
message ListWasmPluginVersionsResponse {
  // List of `WasmPluginVersion` resources.
  repeated WasmPluginVersion wasm_plugin_versions = 1;

  // If there might be more results than those appearing in this response, then
  // `next_page_token` is included. To get the next set of results,
  // call this method again using the value of `next_page_token` as
  // `page_token`.
  string next_page_token = 2;

  // Unreachable resources. Populated when the request attempts to list all
  // resources across all supported locations, while some locations are
  // temporarily unavailable.
  repeated string unreachable = 3;
}

// Request used by the `GetWasmPluginVersion` method.
message GetWasmPluginVersionRequest {
  // Required. A name of the `WasmPluginVersion` resource to get. Must be in
  // the format
  // `projects/{project}/locations/global/wasmPlugins/{wasm_plugin}/versions/{wasm_plugin_version}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "networkservices.googleapis.com/WasmPluginVersion"
    }
  ];
}

// Request used by the `CreateWasmPluginVersion` method.
message CreateWasmPluginVersionRequest {
  // Required. The parent resource of the `WasmPluginVersion` resource. Must be
  // in the format
  // `projects/{project}/locations/global/wasmPlugins/{wasm_plugin}`.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "networkservices.googleapis.com/WasmPluginVersion"
    }
  ];

  // Required. User-provided ID of the `WasmPluginVersion` resource to be
  // created.
  string wasm_plugin_version_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. `WasmPluginVersion` resource to be created.
  WasmPluginVersion wasm_plugin_version = 3
      [(google.api.field_behavior) = REQUIRED];
}

// Request used by the `DeleteWasmPluginVersion` method.
message DeleteWasmPluginVersionRequest {
  // Required. A name of the `WasmPluginVersion` resource to delete. Must be in
  // the format
  // `projects/{project}/locations/global/wasmPlugins/{wasm_plugin}/versions/{wasm_plugin_version}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "networkservices.googleapis.com/WasmPluginVersion"
    }
  ];
}
