syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";

package sink.v1;

service UserDefinedSink {
  // SinkFn writes the Datum to a user defined sink.
  rpc SinkFn(stream DatumRequest) returns (ResponseList);

  // IsReady is the heartbeat endpoint for gRPC.
  rpc IsReady(google.protobuf.Empty) returns (ReadyResponse);
}

message EventTime {
  // event_time is the time associated with each datum.
  google.protobuf.Timestamp event_time = 1;
}

message Watermark {
  // watermark is the monotonically increasing time which denotes completeness for the given time for the given vertex.
  // This watermark can be used to track completeness before persisting to sink.
  google.protobuf.Timestamp watermark = 1;
}

/**
 * DatumRequest represents a datum request element.
 */
message DatumRequest {
  repeated string keys = 1;
  bytes value = 2;
  EventTime event_time = 3;
  Watermark watermark = 4;
  string id = 5;
}

/**
 * ReadyResponse is the health check result.
 */
message ReadyResponse {
  bool ready = 1;
}

/**
 * Response is the individual response of each message written to the sink.
 */
message Response {
  // id is the ID of the message, can be used to uniquely identify the message.
  string id = 1;
  // success denotes the status of persisting to disk. if set to false, it means writing to sink for the message failed.
  bool success = 2;
  // err_msg is the error message, set it if success is set to false.
  string err_msg = 3;
}

/**
 * ResponseList is the list of responses. The number of elements in this list will be equal to the number of Datum
 * elements passed to the SinkFn.
 */
message ResponseList {
  repeated Response responses = 1;
}