option optimize_for = LITE_RUNTIME;
package pb;
message paramRange{
	required string name = 1;
	required float min = 2;
	required float max = 3;
}
message rangeGate{
	required paramRange param = 1;
}
message paramPoly{
	repeated string params = 1;//params.at(0) is x, params.at(1) is y axis
	repeated coordinate vertices = 2;
}
message polygonGate{
	required paramPoly param = 1;
	optional quadGate qg = 2;

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

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

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

message clusterGate{
    required string cluster_method = 1;
}
enum QUADRANT{
	Q1 = 1;//-+
	Q2 = 2;//++
	Q3 = 3;//+-
	Q4 = 4;//--

};
message quadGate{
    required string uid = 1;
    required QUADRANT quadrant = 3;
}
enum GATE_TYPE{
	 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;
	}
message gate{
	required bool neg =1;
	required bool isTransformed =2;
	required bool isGained = 3;
	required GATE_TYPE type = 4;

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

}


message POPSTATS{
	required string statType = 1;
	required 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];
	optional uint32 spline_method = 6;
	optional string caltype = 7;
	optional 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{
	optional uint32 channelRange = 1;
	optional float pos = 2;
	optional float neg = 3;
	optional float widthBasis = 4;
	optional float maxValue = 5;
}
message fasinhTrans{
	optional float length = 1;
	optional float maxRange= 2;
	optional float T = 3;
	optional float A = 4;
	optional float M = 5;;
}
message scaleTrans{
 optional float scale_factor = 1;
 optional float t_scale = 2;
 optional float r_scale = 3;
}
message flinTrans{
	optional float min = 1;
	optional float max = 2;
}
message logTrans{
	optional float offset = 1;
	optional float decade = 2;
	optional float T = 3;
	optional float scale = 4;
	}
message logGML2Trans{
	optional float T = 1;
	optional float M = 2;
}
message logicleTrans{
	optional float T = 1;
	optional float W= 2;
	optional float M = 3;
	optional float A = 4;
	optional float bins = 5;
	optional bool isGml2 = 6;
	optional bool isInverse = 7;

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

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

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

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

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

}

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

message populationTree{
	repeated treeNodes node = 1;

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

	optional COMP comp = 1;
	optional bool isLoaded = 3;

	repeated PARAM transFlag = 4;
	optional trans_local trans = 5;
	optional CytoFrame frame = 6;
}
message CytoFrame {
    required bool is_h5 = 1;
}

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

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

