syntax = "proto3";

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


package sink.v1;

service Sink {
  // SinkFn writes the request to a user defined sink.
  rpc SinkFn(stream SinkRequest) returns (stream SinkResponse);

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

/**
 * SinkRequest represents a request element.
 */
message SinkRequest {
  message Request {
    repeated string keys = 1;
    bytes value = 2;
    google.protobuf.Timestamp event_time = 3;
    google.protobuf.Timestamp watermark = 4;
    string id = 5;
    map<string, string> headers = 6;
  }
  // Required field indicating the request.
  Request request = 1;
  // Required field indicating the status of the request.
  // If eot is set to true, it indicates the end of transmission.
  TransmissionStatus status = 2;
  // optional field indicating the handshake message.
  optional Handshake handshake = 3;
}

/*
 * Handshake message between client and server to indicate the start of transmission.
 */
message Handshake {
  // Required field indicating the start of transmission.
  bool sot = 1;
}

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

/**
 * TransmissionStatus is the status of the transmission.
 */
message TransmissionStatus {
  bool eot = 1;
}

/*
  * Status is the status of the response.
 */
enum Status {
  SUCCESS = 0;
  FAILURE = 1;
  FALLBACK = 2;
}

/**
 * SinkResponse is the individual response of each message written to the sink.
 */
message SinkResponse {
  message Result {
    // id is the ID of the message, can be used to uniquely identify the message.
    string id = 1;
    // status denotes the status of persisting to sink. It can be SUCCESS, FAILURE, or FALLBACK.
    Status status = 2;
    // err_msg is the error message, set it if success is set to false.
    string err_msg = 3;
  }
  repeated Result results = 1;
  optional Handshake handshake = 2;
  optional TransmissionStatus status = 3;
}