syntax = "proto3";
option go_package = "datasource";

package models;

message DatasourceRequest {
  TimeRange timeRange = 1;
  DatasourceInfo datasource = 2;
  repeated Query queries = 3;
}

message Query {
  string refId = 1;
  int64 maxDataPoints = 2;
  int64 intervalMs = 3;
  string modelJson = 4;
}

message TimeRange {
  string fromRaw = 1;
  string toRaw = 2;
  int64 fromEpochMs = 3;
  int64 toEpochMs = 4;
}

message DatasourceResponse {
  repeated QueryResult results = 1;
}

message QueryResult {
  string error = 1;
  string refId = 2;
  string metaJson = 3;
  repeated TimeSeries series = 4;
  repeated Table tables = 5;
}

message Table {
  repeated TableColumn columns = 1;
  repeated TableRow rows = 2;
}

message TableColumn {
  string name = 1;
}

message TableRow {
  repeated RowValue values = 1;
}

message RowValue {
  enum Kind {
    // Field type null.
    TYPE_NULL           = 0;
    // Field type double.
    TYPE_DOUBLE          = 1;
    // Field type int64.
    TYPE_INT64          = 2;
    // Field type bool.
    TYPE_BOOL           = 3;
    // Field type string.
    TYPE_STRING         = 4;
    // Field type bytes.
    TYPE_BYTES          = 5;
  };

  Kind kind = 1;
  double doubleValue = 2;
  int64 int64Value = 3;
  bool boolValue = 4;
  string stringValue = 5;
  bytes bytesValue = 6;
}

message DatasourceInfo {
  int64 id = 1;
  int64 orgId = 2;
  string name = 3;
  string type = 4;
  string url = 5;
  string jsonData = 6;
  map<string,string> decryptedSecureJsonData = 7;
}

message TimeSeries {
  string name = 1;
  map<string, string> tags = 2;
  repeated Point points = 3;
}

message Point {
  int64 timestamp = 1;
  double value = 2;
}

service DatasourcePlugin {
    rpc Query(DatasourceRequest) returns (DatasourceResponse);
}
