syntax = "proto3";

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

package map.v1;

service Map {
  // MapFn applies a function to each map request element.
  rpc MapFn(stream MapRequest) returns (stream MapResponse);

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

/**
 * MapRequest represents a request element.
 */
message MapRequest {
  message Request {
    repeated string keys = 1;
    bytes value = 2;
    google.protobuf.Timestamp event_time = 3;
    google.protobuf.Timestamp watermark = 4;
    map<string, string> headers = 5;
    // Metadata is the metadata of the message
    metadata.Metadata metadata = 6;
  }
  Request request = 1;
  // This ID is used to uniquely identify a map request
  string id = 2;
  optional Handshake handshake = 3;
  optional TransmissionStatus status = 4;
}

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

/*
 * Status message to indicate the status of the message.
 */
message TransmissionStatus {
  bool eot = 1;
}

/**
 * MapResponse represents a response element.
 */
message MapResponse {
  message Result {
    repeated string keys = 1;
    bytes value = 2;
    repeated string tags = 3;
    // Metadata is the metadata of the message
    metadata.Metadata metadata = 4;
    // Per message options to nack back to the source with.
    optional nack_options.NackOptions nack_options = 5;
  }
  repeated Result results = 1;
  // This ID is used to refer the responses to the request it corresponds to.
  string id = 2;
  optional Handshake handshake = 3;
  optional TransmissionStatus status = 4;
}

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