syntax = "proto3";
package pb;
message paramRange{
	string name = 1;
	float min = 2;
	float max = 3;
}
// An arbitrary float value range for use in other messages.
message Range {
  float min = 1;
  float max = 2;
}

message rangeGate{
	paramRange param = 1;
}

message MultiRangeGate {
    string name = 1;
    repeated Range ranges = 2;
}

message paramPoly{
	repeated string params = 1;//params.at(0) is x, params.at(1) is y axis
	repeated coordinate vertices = 2;
}
message polygonGate{
	paramPoly param = 1;
	quadGate qg = 2;

}
message coordinate{
	float x = 1;
	float y = 2;

}
message ellipseGate{
	coordinate mu = 1;// center point
 	repeated coordinate cov = 2;//covariance matrix
 	repeated coordinate antipodal_vertices = 3;
 	float dist = 4;
}
message BOOL_GATE_OP{
	repeated string path = 1;
	uint32 op = 2;
	bool isNot =3;
}

message boolGate{
	repeated BOOL_GATE_OP boolOpSpec = 1;//the gatePaths with the their logical operators
}

message clusterGate{
    string cluster_method = 1;
}
enum QUADRANT{
	Q_UNSPECIFIED = 0;//dummy Q added to ensure the legacy archive defined by proto2 can load
  Q1 = 1;//-+
	Q2 = 2;//++
	Q3 = 3;//+-
	Q4 = 4;//--

};
message quadGate{
    string uid = 1;
    QUADRANT quadrant = 3;
}
enum GATE_TYPE{
   GATE_UNSPECIFIED = 0;//dummy item added to ensure the legacy archive defined by proto2 can load
	 POLYGON_GATE = 1;
	 RANGE_GATE = 2;
	 BOOL_GATE = 3;
	 ELLIPSE_GATE = 4;
	 RECT_GATE = 5;
	 LOGICAL_GATE = 6;
	 ELLIPSOID_GATE = 7;
	 CLUSTER_GATE = 8;
	 QUAD_GATE = 9;
   MULTI_RANGE_GATE = 11;
	}
message gate{
	bool neg =1;
	bool isTransformed =2;
	bool isGained = 3;
	GATE_TYPE type = 4;

	rangeGate rg = 5;
	polygonGate pg = 6;
	ellipseGate eg = 7;
	boolGate bg = 8;
    clusterGate cg = 9;
  MultiRangeGate mrg = 10;

}


message POPSTATS{
	string statType = 1;
	float statVal = 2;
}
enum ind_type {
		BOOL = 0;
		INT = 1;
		ROOT = 2 ;
	}
message calibrationTable{
	repeated float x = 1 [packed = true];
	repeated float y = 2 [packed = true];
	repeated float b = 3 [packed = true];
	repeated float c = 4 [packed = true];
	repeated float d = 5 [packed = true];
	uint32 spline_method = 6;
	string caltype = 7;
	bool flag = 8;
}
enum TRANS_TYPE {
		PB_CALTBL = 0;
		PB_LOG = 1 ;
		PB_LIN = 2;
		PB_FLIN = 3;
		PB_FASIGNH = 4;
		PB_BIEXP = 5;
		PB_LOGICLE = 6;
		PB_LOGGML2 = 7;
		PB_SCALE = 8;
	}
message biexpTrans{
	uint32 channelRange = 1;
	float pos = 2;
	float neg = 3;
	float widthBasis = 4;
	float maxValue = 5;
}
message fasinhTrans{
	float length = 1;
	float maxRange= 2;
	float T = 3;
	float A = 4;
	float M = 5;;
}
message scaleTrans{
 float scale_factor = 1;
 float t_scale = 2;
 float r_scale = 3;
}
message flinTrans{
	float min = 1;
	float max = 2;
}
message logTrans{
	float offset = 1;
	float decade = 2;
	float T = 3;
	float scale = 4;
	}
message logGML2Trans{
	float T = 1;
	float M = 2;
}
message logicleTrans{
	float T = 1;
	float W= 2;
	float M = 3;
	float A = 4;
	float bins = 5;
	bool isGml2 = 6;
	bool isInverse = 7;

}
message transformation{
	calibrationTable calTbl = 1;
	bool isGateOnly = 2;
	string name = 4;
	string channel = 5;
	bool isComputed = 6;
	uint32 type = 12;
	TRANS_TYPE trans_type = 3; //used to handle polymorphism
	biexpTrans bt = 7;
	logTrans lt = 8;
	flinTrans flt = 9;
	scaleTrans st = 10;
	fasinhTrans ft = 11;
	logicleTrans lgt = 13;
	logGML2Trans lgml2t = 14;
}

message trans_pair{
	string name = 1;
	uint64 trans_address = 2;//legacy
    transformation trans = 3;
}

message trans_local{
	repeated trans_pair tp = 1;
	string groupName = 2;
	repeated uint32 sampleIDs = 3 [packed = true];
}

message POPINDICES{
	uint32 nEvents = 1;
	ind_type indtype = 2;
	repeated uint32 iInd = 3 [packed = true];
	bytes bInd = 4;//bits packaged into bytes
}

message nodeProperties{
	string thisName = 1;
	repeated POPSTATS fjStats = 2;
	repeated POPSTATS fcStats = 3;
	bool hidden = 4;
	POPINDICES indices = 5;
	gate thisGate = 6;

}

message treeNodes {
	nodeProperties node = 1;
	uint32 parent = 2;
}

message populationTree{
	repeated treeNodes node = 1;

}
message COMP{
	string cid = 1;
	string prefix = 2;
	string suffix = 3;
	string name = 4;
	string comment = 5;
	repeated string marker = 6;
	repeated float spillOver = 7;
	repeated string detector = 8;
}
message PARAM{
		string param = 1;
		bool log = 2;
		uint32 range = 3;
		uint32 highValue = 4;
		uint32 calibrationIndex = 5;
		//float timestep = 6;
}
message GatingHierarchy {
	populationTree tree = 2;

	COMP comp = 1;
	bool isLoaded = 3;

	repeated PARAM transFlag = 4;
	trans_local trans = 5;
	CytoFrame frame = 6;
}
message CytoFrame {
    bool is_h5 = 1;//deprecated,not used
}

//legacy
message TRANS_TBL{
   uint64 trans_address = 1;
   transformation trans = 2;
}

message GatingSet {
    repeated TRANS_TBL trans_tbl = 2;//legacy
	repeated string sampleName = 1; //a view of ghs
	uint64 globalBiExpTrans = 3;//address of globalBiExpTrans, the actual object stored in trans_tbl
	uint64 globalLinTrans = 4;//address of globalLinTrans, the actual object stored in trans_tbl
	repeated trans_local gTrans = 5;
	string guid = 6;
	string cytolib_verion = 7;
	string pb_verion = 8;
	string h5_verion = 9;
//	repeated gh_tbl ghs = 7;//gh is separately stored due to the size limit of pb message
}

