syntax = "proto3";

package nominal.ingest.v1.internal;

import "buf/validate/validate.proto";
import "nominal/protos/gen/v1/alias.proto";

option java_multiple_files = true;
option java_package = "io.nominal.ingest.v1.internal";

message MarkBatchesCompletedRequest {
  string ingest_job_rid = 1 [
    (buf.validate.field).required = true,
    (nominal.gen.v1.alias) = {java_name: "io.nominal.ingest.api.IngestJobRid"}
  ];
  string dataset_file_id = 2 [
    (buf.validate.field).required = true,
    (nominal.gen.v1.alias) = {java_name: "io.nominal.datasource.DatasetFileId"}
  ];
  repeated int32 batch_ids = 3;
}

message MarkBatchesCompletedResponse {}

// Internal service for inter-service RPCs. Uses a separate package so that
// the gRPC path (nominal.ingest.v1.internal.*) is excluded from public ingress.
service InternalIngestBatchService {
  // Mark the supplied batches for {@code dataset_file_id} as COMPLETED. Within the same
  // transaction, if all batches for the file are now complete, mark the file's ingest
  // status as COMPLETED; if all files for {@code ingest_job_rid} are then in a terminal
  // ingest status (COMPLETED or FAILED), mark the ingest job COMPLETED. Internal-only
  // (service-token auth).
  //
  // Idempotent: re-issuing the same request after success is a no-op. Already-COMPLETED
  // batches/files/jobs are left in place and the cascade short-circuits at each step.
  rpc MarkBatchesCompleted(MarkBatchesCompletedRequest) returns (MarkBatchesCompletedResponse);
}
