syntax = "proto3";

package nominal.ingest.v2;

import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "nominal/protos/gen/v1/alias.proto";
import "nominal/protos/ingest/v2/containerized_ingest.proto";
import "nominal/protos/ingest/v2/file_ingest.proto";
import "nominal/protos/ingest/v2/log_ingest.proto";
import "nominal/protos/ingest/v2/mcap_ingest.proto";
import "nominal/protos/ingest/v2/point_cloud_ingest.proto";
import "nominal/protos/ingest/v2/video_ingest.proto";

option java_multiple_files = true;
option java_package = "io.nominal.ingest.v2";

// Request to submit a V2 ingest job.
message IngestRequest {
  // Existing dataset that all items in this job will ingest into.
  string dataset_rid = 1 [
    (buf.validate.field).required = true,
    (nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.DatasetRid"}
  ];
  repeated string runs_to_expand = 2 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.run.api.RunRid"}];
  // Units of ingest work to submit under one ingest job RID.
  repeated IngestItem items = 3 [(buf.validate.field).repeated.min_items = 1];
  // Tags applied to every item in this ingest job. Item-level tags override these values.
  map<string, string> tags = 4 [(nominal.gen.v1.alias) = {
    key_java_name: "io.nominal.api.TagName"
    value_java_name: "io.nominal.api.TagValue"
  }];
}

// Response from submitting a V2 ingest job.
message IngestResponse {
  // RID for the submitted ingest job.
  string ingest_job_rid = 1 [
    (buf.validate.field).required = true,
    (nominal.gen.v1.alias) = {java_name: "io.nominal.ingest.api.IngestJobRid"}
  ];
}

// One unit of ingest work submitted under a single ingest job.
message IngestItem {
  // Tags applied only to this ingest item. These override request-level tags on conflict.
  map<string, string> tags = 1 [(nominal.gen.v1.alias) = {
    key_java_name: "io.nominal.api.TagName"
    value_java_name: "io.nominal.api.TagValue"
  }];

  oneof item {
    option (buf.validate.oneof) = {required: true};

    FileIngestItem file = 2;
    LogIngestItem log = 3;
    ContainerizedIngestItem containerized = 4;
    VideoIngestItem video = 5;
    PointCloudIngestItem point_cloud = 6;
    McapIngestItem mcap = 7;
    DataflashIngestItem dataflash = 8;
  }
}

// Starts V2 ingest jobs and returns the RID used to track asynchronous progress.
service IngestService {
  // Submit a V2 ingest job.
  rpc Ingest(IngestRequest) returns (IngestResponse) {
    option (google.api.http) = {
      post: "/ingest/v2"
      body: "*"
    };
  }
}
