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

import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/code.proto";

option go_package = "cloud.google.com/go/lustre/apiv1/lustrepb;lustrepb";
option java_multiple_files = true;
option java_outer_classname = "TransferProto";
option java_package = "com.google.cloud.lustre.v1";

// Type of transfer that occurred.
enum TransferType {
  // Zero is an illegal value.
  TRANSFER_TYPE_UNSPECIFIED = 0;

  // Imports to Lustre.
  IMPORT = 1;

  // Exports from Lustre.
  EXPORT = 2;
}

// Message for importing data to Lustre.
message ImportDataRequest {
  // A Cloud Storage URI of a folder to import file data from, in the
  // form of `gs://<bucket_name>/<path_inside_bucket>/`.
  oneof source {
    // The Cloud Storage source bucket and, optionally, path inside the bucket.
    // If a path inside the bucket is specified, it must end with a forward
    // slash (`/`).
    GcsPath gcs_path = 2;
  }

  // The destination of the data transfer.
  oneof destination {
    // Lustre path destination.
    LustrePath lustre_path = 3;
  }

  // Required. The name of the Managed Lustre instance in the format
  // `projects/{project}/locations/{location}/instances/{instance}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "lustre.googleapis.com/Instance" }
  ];

  // Optional. UUID to identify requests.
  string request_id = 4 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];

  // Optional. User-specified service account used to perform the transfer.
  // If unspecified, the default Managed Lustre service agent will be used.
  string service_account = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "iam.googleapis.com/ServiceAccount"
    }
  ];
}

// Export data from Managed Lustre to a Cloud Storage bucket.
message ExportDataRequest {
  // The source of the data transfer.
  oneof source {
    // The root directory path to the Managed Lustre file system. Must start
    // with `/`. Default is `/`.
    LustrePath lustre_path = 2;
  }

  // The destination of the data transfer.
  oneof destination {
    // The URI to a Cloud Storage bucket, or a path within a bucket, using
    // the format `gs://<bucket_name>/<optional_path_inside_bucket>/`. If a
    // path inside the bucket is specified, it must end with a forward slash
    // (`/`).
    GcsPath gcs_path = 3;
  }

  // Required. The name of the Managed Lustre instance in the format
  // `projects/{project}/locations/{location}/instances/{instance}`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "lustre.googleapis.com/Instance" }
  ];

  // Optional. UUID to identify requests.
  string request_id = 4 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];

  // Optional. User-specified service account used to perform the transfer.
  // If unspecified, the Managed Lustre service agent is used.
  string service_account = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = {
      type: "iam.googleapis.com/ServiceAccount"
    }
  ];
}

// Response message for ExportData.
message ExportDataResponse {}

// Response message for ImportData.
message ImportDataResponse {}

// Metadata of the export data operation.
message ExportDataMetadata {
  // Data transfer operation metadata.
  TransferOperationMetadata operation_metadata = 1;

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

  // Output only. The time the operation finished running.
  google.protobuf.Timestamp end_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Server-defined resource path for the target of the operation.
  string target = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Name of the verb executed by the operation.
  string verb = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Human-readable status of the operation, if any.
  string status_message = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Identifies whether the user has requested cancellation
  // of the operation. Operations that have successfully been cancelled
  // have
  // [google.longrunning.Operation.error][google.longrunning.Operation.error]
  // value with a [google.rpc.Status.code][google.rpc.Status.code] of 1,
  // corresponding to `Code.CANCELLED`.
  bool requested_cancellation = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. API version used to start the operation.
  string api_version = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Metadata of the import data operation.
message ImportDataMetadata {
  // Data transfer operation metadata.
  TransferOperationMetadata operation_metadata = 1;

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

  // Output only. The time the operation finished running.
  google.protobuf.Timestamp end_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Server-defined resource path for the target of the operation.
  string target = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Name of the verb executed by the operation.
  string status_message = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Identifies whether the user has requested cancellation
  // of the operation. Operations that have successfully been cancelled
  // have
  // [google.longrunning.Operation.error][google.longrunning.Operation.error]
  // value with a [google.rpc.Status.code][google.rpc.Status.code] of 1,
  // corresponding to `Code.CANCELLED`.
  bool requested_cancellation = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. API version used to start the operation.
  string api_version = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Specifies a Cloud Storage bucket and, optionally, a path inside the bucket.
message GcsPath {
  // Required. The URI to a Cloud Storage bucket, or a path within a bucket,
  // using the format `gs://<bucket_name>/<optional_path_inside_bucket>/`. If a
  // path inside the bucket is specified, it must end with a forward slash
  // (`/`).
  string uri = 1 [(google.api.field_behavior) = REQUIRED];
}

// The root directory path to the Lustre file system.
message LustrePath {
  // Optional. The root directory path to the Managed Lustre file system. Must
  // start with
  // `/`. Default is `/`. If you're importing data into Managed Lustre, any
  // path other than the default must already exist on the file system.
  string path = 1 [(google.api.field_behavior) = OPTIONAL];
}

// A collection of counters that report the progress of a transfer operation.
message TransferCounters {
  // Objects found in the data source that are scheduled to be transferred,
  // excluding any that are filtered based on object conditions or skipped due
  // to sync.
  int64 found_objects_count = 1;

  // Total number of bytes found in the data source that are scheduled to be
  // transferred, excluding any that are filtered based on object conditions or
  // skipped due to sync.
  int64 bytes_found_count = 2;

  // Objects in the data source that are not transferred because they already
  // exist in the data destination.
  int64 objects_skipped_count = 3;

  // Bytes in the data source that are not transferred because they already
  // exist in the data destination.
  int64 bytes_skipped_count = 4;

  // Objects that are copied to the data destination.
  int64 objects_copied_count = 5;

  // Bytes that are copied to the data destination.
  int64 bytes_copied_count = 6;

  // Output only. Objects that are failed to write to the data destination.
  int64 objects_failed_count = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Bytes that are failed to write to the data destination.
  int64 bytes_failed_count = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// An entry describing an error that has occurred.
message ErrorLogEntry {
  // Required. A URL that refers to the target (a data source, a data sink,
  // or an object) with which the error is associated.
  string uri = 1 [(google.api.field_behavior) = REQUIRED];

  // A list of messages that carry the error details.
  repeated string error_details = 2;
}

// A summary of errors by error code, plus a count and sample error log
// entries.
message ErrorSummary {
  // Required.
  google.rpc.Code error_code = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Count of this type of error.
  int64 error_count = 2 [(google.api.field_behavior) = REQUIRED];

  // Error samples.
  //
  // At most 5 error log entries are recorded for a given
  // error code for a single transfer operation.
  repeated ErrorLogEntry error_log_entries = 3;
}

// Represents the metadata of the long-running transfer operation.
message TransferOperationMetadata {
  // The source of transfer operation.
  oneof source {
    // Output only. Lustre source.
    LustrePath source_lustre_path = 3
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Cloud Storage source.
    GcsPath source_gcs_path = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // The destination of transfer operation.
  oneof destination {
    // Output only. Cloud Storage destination.
    GcsPath destination_gcs_path = 5
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Lustre destination.
    LustrePath destination_lustre_path = 6
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Output only. The progress of the transfer operation.
  TransferCounters counters = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The type of transfer occurring.
  TransferType transfer_type = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Error summary about the transfer operation
  repeated ErrorSummary error_summaries = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];
}
