syntax = "proto3";

option go_package = "github.com/numaproj/numaflow-go/pkg/apis/proto/map/v1";

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.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;
  }
  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;
  }
  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;
}
