// 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.storagebatchoperations.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/storagebatchoperations/v1/storage_batch_operations_types.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.StorageBatchOperations.V1";
option go_package = "cloud.google.com/go/storagebatchoperations/apiv1/storagebatchoperationspb;storagebatchoperationspb";
option java_multiple_files = true;
option java_outer_classname = "StorageBatchOperationsProto";
option java_package = "com.google.cloud.storagebatchoperations.v1";
option php_namespace = "Google\\Cloud\\StorageBatchOperations\\V1";
option ruby_package = "Google::Cloud::StorageBatchOperations::V1";

// Storage Batch Operations offers a managed experience to perform batch
// operations on millions of Cloud Storage objects in a serverless fashion. With
// this service, you can automate and simplify large scale API operations
// performed on Cloud Storage objects.
service StorageBatchOperations {
  option (google.api.default_host) = "storagebatchoperations.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Lists Jobs in a given project.
  rpc ListJobs(ListJobsRequest) returns (ListJobsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/jobs"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets a batch job.
  rpc GetJob(GetJobRequest) returns (Job) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/jobs/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a batch job.
  rpc CreateJob(CreateJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/jobs"
      body: "job"
    };
    option (google.api.method_signature) = "parent,job,job_id";
    option (google.longrunning.operation_info) = {
      response_type: "Job"
      metadata_type: "OperationMetadata"
    };
  }

  // Deletes a batch job.
  rpc DeleteJob(DeleteJobRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/jobs/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Cancels a batch job.
  rpc CancelJob(CancelJobRequest) returns (CancelJobResponse) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/jobs/*}:cancel"
      body: "*"
    };
    option (google.api.method_signature) = "name";
  }
}

// Message for request to list Jobs
message ListJobsRequest {
  // Required. Format: projects/{project_id}/locations/global.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "storagebatchoperations.googleapis.com/Job"
    }
  ];

  // Optional. Filters results as defined by https://google.aip.dev/160.
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The list page size. default page size is 100.
  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The list page token.
  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Field to sort by. Supported fields are name, create_time.
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Message for response to listing Jobs
message ListJobsResponse {
  // A list of storage batch jobs.
  repeated Job jobs = 1;

  // A token identifying a page of results.
  string next_page_token = 2;

  // Locations that could not be reached.
  repeated string unreachable = 3;
}

// Message for getting a Job
message GetJobRequest {
  // Required. `name` of the job to retrieve.
  // Format: projects/{project_id}/locations/global/jobs/{job_id} .
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "storagebatchoperations.googleapis.com/Job"
    }
  ];
}

// Message for creating a Job
message CreateJobRequest {
  // Required. Value for parent.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "storagebatchoperations.googleapis.com/Job"
    }
  ];

  // Required. The optional `job_id` for this Job . If not
  // specified, an id is generated. `job_id` should be no more than 128
  // characters and must include only characters available in DNS names, as
  // defined by RFC-1123.
  string job_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The resource being created
  Job job = 3 [(google.api.field_behavior) = REQUIRED];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID in case you need to retry your request. Requests with same
  // `request_id` will be ignored for at least 60 minutes since the first
  // request. The request ID must be a valid UUID with the exception that zero
  // UUID is not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Message for Job to Cancel
message CancelJobRequest {
  // Required. The `name` of the job to cancel.
  // Format: projects/{project_id}/locations/global/jobs/{job_id}.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "storagebatchoperations.googleapis.com/Job"
    }
  ];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID in case you need to retry your request. Requests with same
  // `request_id` will be ignored for at least 60 minutes since the first
  // request. The request ID must be a valid UUID with the exception that zero
  // UUID is not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Message for deleting a Job
message DeleteJobRequest {
  // Required. The `name` of the job to delete.
  // Format: projects/{project_id}/locations/global/jobs/{job_id} .
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "storagebatchoperations.googleapis.com/Job"
    }
  ];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID in case you need to retry your request. Requests with same
  // `request_id` will be ignored for at least 60 minutes since the first
  // request. The request ID must be a valid UUID with the exception that zero
  // UUID is not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 2 [(google.api.field_behavior) = OPTIONAL];
}

// Message for response to cancel Job.
message CancelJobResponse {}

// Represents the metadata of the long-running operation.
message OperationMetadata {
  // Output only. The unique operation resource name.
  // Format: projects/{project}/locations/global/operations/{operation}.
  string operation = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // 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. Identifies whether the user has requested cancellation
  // of the operation. Operations that have been cancelled successfully
  // 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][google.rpc.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];

  // Output only. The Job associated with the operation.
  Job job = 10 [(google.api.field_behavior) = OUTPUT_ONLY];
}
