syntax = "proto3";
package proto;

import "google/protobuf/struct.proto";

// Empty message
message Empty {}

// Node service - plugin side
service Node {
    rpc Init(InitRequest) returns (Empty);
    rpc OnCreate(OnCreateRequest) returns (OnCreateResponse);
    rpc OnMessage(OnMessageRequest) returns (OnMessageResponse);
    rpc OnClose(OnCloseRequest) returns (OnCloseResponse);
    rpc GetCapabilities(Empty) returns (PGetCapabilitiesResponse);
}

message InitRequest {
    uint32 event_server = 1;
}

message OnCreateRequest {
    string name = 1;
    bytes config = 2;
}

message OnCreateResponse {}

message OnMessageRequest {
    string guid = 1;
    bytes in_message = 2;
}

message OnMessageResponse {
    bytes out_message = 1;
}

message OnCloseRequest {
    string guid = 1;
}

message OnCloseResponse {}

message PGetCapabilitiesResponse {
    uint64 capabilities = 1;
}

// RuntimeHelper service - host side, called by plugin
service RuntimeHelper {
    rpc Close(Empty) returns (Empty);
    rpc Debug(DebugRequest) returns (Empty);
    rpc EmitFlowEvent(EmitFlowEventRequest) returns (Empty);
    rpc EmitInput(EmitInputRequest) returns (Empty);
    rpc EmitOutput(EmitOutputRequest) returns (Empty);
    rpc EmitError(EmitErrorRequest) returns (Empty);
    rpc GetVaultItem(GetVaultItemRequest) returns (GetVaultItemResponse);
    rpc SetVaultItem(SetVaultItemRequest) returns (SetVaultItemResponse);
    rpc GetVariable(GetVariableRequest) returns (GetVariableResponse);
    rpc SetVariable(SetVariableRequest) returns (Empty);
    rpc GetRobotInfo(Empty) returns (GetRobotInfoResponse);
    rpc AppRequest(AppRequestRequest) returns (AppRequestResponse);
    rpc AppRequestV2(AppRequestV2Request) returns (AppRequestV2Response);
    rpc AppPublish(AppPublishRequest) returns (Empty);
    rpc AppDownload(AppDownloadRequest) returns (AppDownloadResponse);
    rpc AppUpload(AppUploadRequest) returns (AppUploadResponse);
    rpc GatewayRequest(GatewayRequestRequest) returns (GatewayRequestResponse);
    rpc ProxyRequest(HttpRequest) returns (HttpResponse);
    rpc IsRunning(Empty) returns (IsRunningResponse);
    rpc GetPortConnections(GetPortConnectionsRequest) returns (GetPortConnectionsResponse);
    rpc GetInstanceAccess(Empty) returns (GetInstanceAccessResponse);
}

message DebugRequest {
    string guid = 1;
    string name = 2;
    bytes message = 3;
}

message EmitFlowEventRequest {
    string guid = 1;
    string name = 2;
}

message EmitInputRequest {
    string guid = 1;
    bytes input = 2;
}

message EmitOutputRequest {
    string guid = 1;
    bytes output = 2;
    int32 port = 3;
}

message EmitErrorRequest {
    string guid = 1;
    string name = 2;
    string message = 3;
}

message Variable {
    string name = 1;
    string scope = 2;
    bytes payload = 3;
}

message GetVaultItemRequest {
    string item_id = 1;
    string vault_id = 2;
}

message GetVaultItemResponse {
    google.protobuf.Struct item = 1;
}

message SetVaultItemRequest {
    string item_id = 1;
    string vault_id = 2;
    bytes data = 3;
}

message SetVaultItemResponse {
    google.protobuf.Struct item = 1;
}

message GetVariableRequest {
    Variable variable = 1;
}

message GetVariableResponse {
    google.protobuf.Struct value = 1;
}

message SetVariableRequest {
    Variable variable = 1;
    google.protobuf.Struct value = 2;
}

message GetRobotInfoResponse {
    google.protobuf.Struct robot = 1;
}

message AppRequestRequest {
    bytes request = 1;
    int32 timeout = 2;
}

message AppRequestResponse {
    bytes response = 1;
}

message AppRequestV2Request {
    bytes request = 1;
}

message AppRequestV2Response {
    bytes response = 1;
}

message AppPublishRequest {
    bytes request = 1;
}

message AppDownloadRequest {
    string id = 1;
    string directory = 2;
    string file = 3;
}

message AppDownloadResponse {
    string path = 1;
}

message AppUploadRequest {
    string id = 1;
    string path = 2;
}

message AppUploadResponse {
    string url = 1;
}

message GatewayRequestRequest {
    string method = 1;
    string endpoint = 2;
    string body = 3;
    map<string, string> headers = 4;
}

message GatewayRequestResponse {
    int32 status_code = 1;
    bytes body = 2;
    map<string, string> headers = 3;
}

message HttpRequest {
    string method = 1;
    string url = 2;
    map<string, string> headers = 3;
    bytes body = 4;
}

message HttpResponse {
    int32 status_code = 1;
    bytes body = 2;
    map<string, string> headers = 3;
}

message IsRunningResponse {
    bool is_running = 1;
}

message GetPortConnectionsRequest {
    string guid = 1;
    int32 port = 2;
}

message NodeInfo {
    string type = 1;
    string version = 2;
    bytes config = 3;
}

message GetPortConnectionsResponse {
    repeated NodeInfo nodes = 1;
}

message GetInstanceAccessResponse {
    string amq_endpoint = 1;
    string api_endpoint = 2;
    string access_token = 3;
}
