syntax = "proto3";

package svc.query.v1;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "types/v1/cursor.proto";
import "types/v1/logevent.proto";
import "types/v1/logquery.proto";
import "types/v1/query.proto";
import "types/v1/session.proto";
import "types/v1/symbol.proto";
import "types/v1/types.proto";

option go_package = "svc/query/v1;queryv1";

service QueryService {
  rpc SummarizeEvents(SummarizeEventsRequest) returns (SummarizeEventsResponse);

  rpc WatchQuery(WatchQueryRequest) returns (stream WatchQueryResponse);

  // rpc CreateWatch(CreateWatchRequest) returns (CreateWatchResponse);
  // rpc GetWatch(GetWatchRequest) returns (GetWatchResponse);
  // rpc UpdateWatch(UpdateWatchRequest) returns (UpdateWatchResponse);
  // rpc ListWatch(ListWatchRequest) returns (ListWatchResponse);
  // rpc DeleteWatch(DeleteWatchRequest) returns (GetWatchResponse);

  rpc Parse(ParseRequest) returns (ParseResponse);
  rpc Query(QueryRequest) returns (QueryResponse);
  rpc ListSymbols(ListSymbolsRequest) returns (ListSymbolsResponse);
}

message SummarizeEventsRequest {
  int64 environment_id = 1;
  optional google.protobuf.Timestamp from = 2;
  optional google.protobuf.Timestamp to = 3;
  uint32 bucket_count = 4;
}

message SummarizeEventsResponse {
  google.protobuf.Duration bucket_width = 1;
  repeated Bucket buckets = 2;

  message Bucket {
    google.protobuf.Timestamp ts = 1;
    uint64 event_count = 2;
  }
}

message WatchQueryRequest {
  int64 environment_id = 1;

  message UnstablePlaintext {
    google.protobuf.Timestamp from = 1;
    google.protobuf.Timestamp to = 2;
    string query = 3;
  }

  types.v1.LogQuery query = 2;
  UnstablePlaintext plaintext_query = 201;
}

message WatchQueryResponse {
  repeated types.v1.LogEventGroup events = 1;
}

message ParseRequest {
  string query = 1;
}

message ParseResponse {
  types.v1.LogQuery query = 1;
  types.v1.DataStreamType data_type = 2;
}

message QueryRequest {
  int64 environment_id = 101;
  types.v1.Cursor cursor = 102;
  int32 limit = 103;
  types.v1.LogQuery query = 2;
}

message QueryResponse {
  types.v1.Cursor next = 100;
  types.v1.Data data = 200;
}

message ListSymbolsRequest {
  int64 environment_id = 101;
  types.v1.Cursor cursor = 102;
  int32 limit = 103;
}

message ListSymbolsResponse {
  message ListItem {
    types.v1.Symbol symbol = 2;
  }
  types.v1.Cursor next = 100;
  repeated ListItem items = 200;
}
