package com.gyee.alarm.rule.expression;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class AlarmExpression {

    private String funCode;

    private String funType;

    private String originalExpression;

    private String expression;

    private List<String> varList;

    private List<AlarmExpression> children;

    private AlarmExpression parent;

    private String ruleId;

    private ArrayList<String> funParams;

//    private boolean isOpened;

//    public AlarmExpression(String exp) {
//
//    }

    public ArrayList<String> getAllUniformCodes() {
        ArrayList<String> result = new ArrayList<>();
        if (varList != null && varList.size() > 0) {
            for (String var : varList) {
                if (var.startsWith(Analyzer.FUNCODE) == false)
                    result.add(var);
            }
        }

        if (children != null && children.size() > 0) {
            for (AlarmExpression subExp : children) {
                ArrayList<String> r2 = subExp.getAllUniformCodes();
                if (r2.size() > 0) {
                    for (String svar : r2) {
                        if (svar.startsWith(Analyzer.FUNCODE) == false)
                            result.add(svar);
                    }
                }
            }
        }

        return result;
    }

    @Override
    public String toString() {
        return expression;
    }
}
