// 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/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 = "CollectServiceProto";
option java_package = "com.google.cloud.apihub.v1";
option php_namespace = "Google\\Cloud\\ApiHub\\V1";
option ruby_package = "Google::Cloud::ApiHub::V1";

// This service exposes methods used for collecting various types of data from
// different first party and third party sources and push it to Hub's collect
// layer.
service ApiHubCollect {
  option (google.api.default_host) = "apihub.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Collect API data from a source and push it to Hub's collect layer.
  rpc CollectApiData(CollectApiDataRequest)
      returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{location=projects/*/locations/*}:collectApiData"
      body: "*"
    };
    option (google.api.method_signature) = "location,collection_type,api_data";
    option (google.longrunning.operation_info) = {
      response_type: "CollectApiDataResponse"
      metadata_type: "OperationMetadata"
    };
  }
}

// The type of the collect request.
enum CollectionType {
  // The default value. This value is used if the collection type is omitted.
  COLLECTION_TYPE_UNSPECIFIED = 0;

  // The collection type is upsert. This should be used when an API is created
  // or updated at the source.
  COLLECTION_TYPE_UPSERT = 1;

  // The collection type is delete. This should be used when an API is deleted
  // at the source.
  COLLECTION_TYPE_DELETE = 2;
}

// The CollectApiData method's request.
message CollectApiDataRequest {
  // Required. The regional location of the API hub instance and its resources.
  // Format: `projects/{project}/locations/{location}`
  string location = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // Required. The type of collection. Applies to all entries in
  // [api_data][google.cloud.apihub.v1.CollectApiDataRequest.api_data].
  CollectionType collection_type = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The plugin instance collecting the API data.
  // Format:
  // `projects/{project}/locations/{location}/plugins/{plugin}/instances/{instance}`.
  string plugin_instance = 3 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "apihub.googleapis.com/PluginInstance"
    }
  ];

  // Required. The action ID to be used for collecting the API data.
  // This should map to one of the action IDs specified
  // in action configs in the plugin.
  string action_id = 4 [(google.api.field_behavior) = REQUIRED];

  // Required. The API data to be collected.
  ApiData api_data = 5 [(google.api.field_behavior) = REQUIRED];
}

// The API data to be collected.
message ApiData {
  // The data to be collected.
  oneof Data {
    // Optional. The list of API metadata.
    ApiMetadataList api_metadata_list = 1
        [(google.api.field_behavior) = OPTIONAL];
  }
}

// The message to hold repeated API metadata.
message ApiMetadataList {
  // Required. The list of API metadata.
  repeated APIMetadata api_metadata = 1
      [(google.api.field_behavior) = REQUIRED];
}

// The API metadata.
message APIMetadata {
  // Required. The API resource to be pushed to Hub's collect layer. The ID of
  // the API resource will be generated by Hub to ensure uniqueness across all
  // APIs across systems.
  Api api = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The list of versions present in an API resource.
  repeated VersionMetadata versions = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The unique identifier of the API in the system where it was
  // originally created.
  string original_id = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Timestamp indicating when the API was created at the source.
  google.protobuf.Timestamp original_create_time = 4
      [(google.api.field_behavior) = OPTIONAL];

  // Required. Timestamp indicating when the API was last updated at the source.
  google.protobuf.Timestamp original_update_time = 5
      [(google.api.field_behavior) = REQUIRED];
}

// The metadata associated with a version of the API resource.
message VersionMetadata {
  // Required. Represents a version of the API resource in API hub. The ID of
  // the version will be generated by Hub.
  Version version = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The specs associated with this version.
  // Note that an API version can be associated with multiple specs.
  repeated SpecMetadata specs = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The deployments linked to this API version.
  // Note: A particular API version could be deployed to multiple deployments
  // (for dev deployment, UAT deployment, etc.)
  repeated DeploymentMetadata deployments = 4
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The unique identifier of the version in the system where it was
  // originally created.
  string original_id = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Timestamp indicating when the version was created at the source.
  google.protobuf.Timestamp original_create_time = 6
      [(google.api.field_behavior) = OPTIONAL];

  // Required. Timestamp indicating when the version was last updated at the
  // source.
  google.protobuf.Timestamp original_update_time = 7
      [(google.api.field_behavior) = REQUIRED];
}

// The metadata associated with a spec of the API version.
message SpecMetadata {
  // Required. The spec resource to be pushed to Hub's collect layer. The ID of
  // the spec will be generated by Hub.
  Spec spec = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The unique identifier of the spec in the system where it was
  // originally created.
  string original_id = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Timestamp indicating when the spec was created at the source.
  google.protobuf.Timestamp original_create_time = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Required. Timestamp indicating when the spec was last updated at the
  // source.
  google.protobuf.Timestamp original_update_time = 4
      [(google.api.field_behavior) = REQUIRED];
}

// The metadata associated with a deployment.
message DeploymentMetadata {
  // Required. The deployment resource to be pushed to Hub's collect layer. The
  // ID of the deployment will be generated by Hub.
  Deployment deployment = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The unique identifier of the deployment in the system where it
  // was originally created.
  string original_id = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Timestamp indicating when the deployment was created at the
  // source.
  google.protobuf.Timestamp original_create_time = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Required. Timestamp indicating when the deployment was last updated at the
  // source.
  google.protobuf.Timestamp original_update_time = 4
      [(google.api.field_behavior) = REQUIRED];
}

// The CollectApiData method's response.
message CollectApiDataResponse {}
