syntax = "proto3";

package proto;

// ********** SERVICE DEFINITION **********

// cxMateService defines a cxMate compatible service implementation
service cxMateService {
  // StreamNetworks transfers one or more networks to and from the service.
  rpc StreamNetworks (stream NetworkElement) returns (stream NetworkElement) {}
}

// NetworkElement is a wrapper for all of the cxMate supported element types.
message NetworkElement {
  string label = 1;
  oneof element {
    Parameter parameter = 2;
    string json = 3;
    Node node = 4;
    Edge edge = 5;
    NodeAttribute nodeAttribute = 6;
    EdgeAttribute edgeAttribute = 7;
    NetworkAttribute networkAttribute = 8;
    CartesianCoordinate CartesianCoordinate = 9;
    CyGroup cyGroup = 10;
    CyView cyView = 11;
    CyVisualProperty cyVisualProperty = 12;
    CyHiddenAttribute cyHiddenAttribute = 13;
    CyNetworkRelation cyNetworkRelation = 14;
    CySubNetwork cySubNetwork = 15;
    CyTableColumn cyTableColumn = 16;
    NdexStatus ndexStatus = 17;
    Citation citation = 18;
    NodeCitations nodeCitations = 19;
    EdgeCitations edgeCitations = 20;
    Support support = 21;
    NodeSupportance nodeSupportance = 22;
    EdgeSupportance edgeSupportance = 23;
    FunctionTerm functionTerm = 24;
    ReifiedEdge reifiedEdge = 25;
  }
}

// ********* SERVICE ELEMENTS *********
// Elements that do no exist in the network, but pass service information to and from the service.

// Parameter represents a service parameter.
message Parameter {
  string name = 1;
  string format = 2;
  oneof value {
    string stringValue = 3;
    bool booleanValue = 4;
    int64 integerValue = 5;
    double numberValue = 6;
  }
}

// ********** BASE ELEMENTS **********
// Elements common to all CX networks

// aspect: node
// Node represents a single node in a network.
message Node {
  int64 id = 1 [ json_name = "@id" ];
  string name = 2 [ json_name = "n" ];
  string represents = 3 [ json_name = "r" ];
}

// aspect: edge
// Edge represents a single edge in a network.
message Edge {
  int64 id = 1 [ json_name = "@id" ];
  int64 sourceId = 2 [ json_name = "s" ];
  int64 targetId = 3 [ json_name = "t" ];
  string interaction = 4 [ json_name = "i" ];
}

// aspect: nodeAttribute
// NodeAttribute represents a single attribute attached to a node.
message NodeAttribute {
  int64 nodeId = 1 [ json_name = "po" ];
  string name = 2 [ json_name = "n" ];
  string value = 3 [ json_name = "v" ];
  string type = 4 [ json_name = "d" ];
  int64 subnetId = 5 [ json_name = "s" ];
}

// aspect: edgeAttribute
// EdgeAttribute represents a single attribute attached to an edge.
message EdgeAttribute {
  int64 edgeId = 1 [ json_name = "po" ];
  string name = 2 [ json_name = "n" ];
  string value = 3 [ json_name = "v" ];
  string type = 4 [ json_name = "d" ];
  int64 subnetId = 5 [ json_name = "s" ];
}

// aspect: networkAttributes
// NetworkAttribute represents a single attribute attached to a network.
message NetworkAttribute {
  string name = 1 [ json_name = "n" ];
  string value = 2 [ json_name = "v" ];
  string type = 3 [ json_name = "d" ];
  int64 subnetId = 4 [ json_name = "s" ];
}

// aspect: cartesianLayout
// CartesianCoordinate represents an (x,y,(z)) coordinate attached to a node.
message CartesianCoordinate {
  int64 nodeId = 1 [ json_name = "node" ];
  double x = 2 [ json_name = "x" ];
  double y = 3 [ json_name = "y" ];
  double z = 4 [ json_name = "z" ];
  int64 viewId = 5 [ json_name = "view" ];
}

// ********* CYTOSCAPE ELEMENTS *********
// Elements used by Cytoscape to represent Cytoscape constructs

// aspect: cyGroups
// CyGroup represents a Cytoscape group.
message CyGroup {
  int64 id = 1 [ json_name = "@id" ];
  int64 view = 2 [ json_name = "view" ];
  string name = 3 [ json_name = "name" ];
  repeated int64 nodes = 4 [ json_name = "nodes" ];
  repeated int64 externalEdges = 5 [ json_name = "external_edge" ];
  repeated int64 internalEdges = 6 [ json_name = "internal_edges" ];
}

// aspect: cyViews
// CyView represents a Cytoscape view.
message CyView {
  int64 id = 1 [ json_name = "@id" ];
  int64 subnetId = 2 [ json_name = "s" ];
}

// aspect: cyVisualProperties
// CyVisualProperty represents a Cytoscape visual property.
message CyVisualProperty {
  string owner = 1 [ json_name = "properties_of" ];
  int64 ownerId =2 [ json_name = "applies_to" ];
  int64 view = 4 [ json_name = "view" ];
  map<string, string> properties = 5 [ json_name = "properties" ];
  map<string, string> dependencies = 6 [ json_name = "dependencies" ];
  map<string, bytes> mappings = 7 [ json_name = "mappings" ];
}

// aspect: cyHiddenAttributes
// CyHiddenAttribute represents a Cytoscape hidden attribute.
message CyHiddenAttribute {
  string name = 1 [ json_name = "n" ];
  string value = 2 [ json_name = "v" ];
  string type = 3 [ json_name = "d" ];
  int64 subnetId = 4 [ json_name = "s" ];
}

// aspect: cyNetworkRelations
// CyNetworkRelation represents a relationship between two Cytoscape networks.
message CyNetworkRelation {
  int64 parentId = 1 [ json_name = "p" ];
  int64 childId = 2 [ json_name = "c" ];
  string relationship = 3 [ json_name = "r" ];
  string name = 4 [ json_name = "name" ];
}

// aspect: cySubNetworks
// CySubNetwork represents a Cytoscape collection subnetwork.
message CySubNetwork {
  int64 id = 1 [ json_name = "@id" ];
  repeated int64 edges = 2 [ json_name = "edges" ];
  repeated int64 nodes = 3 [ json_name = "nodes" ];
}

// aspect: cyTableColumns
// CyTableColumn represents a Cytoscape column.
message CyTableColumn {
  string name = 1 [ json_name = "name" ];
  string type = 2 [ json_name = "type" ];
  string owner = 3 [ json_name = "owner" ];
  int64 subnetId = 4 [ json_name = "applies_to" ];
}

// *********** NDEx ELEMENTS ***********
// Elements used by NDEx to represent NDEx constructs

// aspect: ndexStatus
// NdexStatus represents the status of a network on an NDEx server.
message NdexStatus {
  string id = 1 [ json_name = "externalId" ];
  string location = 2 [ json_name = "ndexServerURI" ];
  string owner = 3 [ json_name = "owner" ];
  string creationTime = 4 [ json_name = "creationTime" ];
  bool readOnly = 5 [ json_name = "readOnly" ];
  string visibility = 6 [ json_name = "visibility" ];
  int64 edgeCount = 7 [ json_name = "edgeCount" ];
  int64 nodeCount = 8 [ json_name = "nodeCount" ];
}

// aspect: citations
// Citation specifies a literature reference to a network.
message Citation {
  string id = 1 [ json_name = "@id" ];
  string title = 2 [ json_name = "dc:title" ];
  string description = 3 [ json_name = "dc:description" ];
  string contributor = 4 [ json_name = "dc:contributor" ];
  string identifier = 5 [ json_name = "dc:identifier" ];
  string type = 6 [ json_name = "dc:type" ];
  repeated CitationAttribute attributes = 7 [ json_name = "attributes" ];
}

// CitationAttribute holds an attribute of a citation.
message CitationAttribute {
  string name = 1 [ json_name = "n" ];
  string value = 2 [ json_name = "v" ];
  string type = 3 [ json_name = "t" ];
}

// aspect: nodeCitations
// NodeCitations creates a series of nodes to citations mappings.
message NodeCitations {
  repeated int64 nodes = 1 [ json_name = "citations" ];
  repeated int64 citations = 2 [ json_name = "po" ];
}

// aspect: edgeCitations
// EdgeCitations creates a series of edges to citations mappings.
message EdgeCitations {
  repeated int64 edges = 1 [ json_name = "citations" ];
  repeated int64 citations = 2 [ json_name = "po" ];
}

// aspect: supports
// Support specifies text that can support one or more nodes or edges in a network.
message Support {
  int64 id = 1 [ json_name = "@id" ];
  int64 citationId = 2 [ json_name = "citation" ];
  string text = 3 [ json_name = "text" ];
  repeated SupportAttribute attributes = 4 [ json_name = "attributes" ];
}

// SupportAttribute holds an attribute of a supportant.
message SupportAttribute {
  string name = 1 [ json_name = "n" ];
  string value = 2 [ json_name = "v" ];
  string type = 3 [ json_name = "t" ];
}

// aspect: nodeSupports
// NodeSupportance provides supportance for a series of nodes.
message NodeSupportance {
  repeated int64 nodes = 1 [ json_name = "nodes" ];
  repeated int64 supportance = 2 [ json_name = "po" ];
}

// aspect: edgeSupports
// EdgeSupportance provides supportance for a series of edges.
message EdgeSupportance {
  repeated int64 edges = 1 [ json_name = "edges" ];
  repeated int64 supportance = 2 [ json_name = "po" ];
}

// aspect: functionTerms
// FuntionTerm link nodes with expressions that define the meaning of the node.
message FunctionTerm {
  int64 nodeId = 1 [ json_name = "po" ];
  string function = 2 [ json_name = "f" ];
  repeated string arguments = 3 [ json_name = "args" ];
}

// reifiedEdges: reifiedEdges
// ReifiedEdge logically turns a node into an edge.
message ReifiedEdge {
  int64 edgeId = 1 [ json_name = "edge" ];
  int64 nodeId = 2 [ json_name = "node" ];
}
