package _VisualDVM.ProjectData.SapforData.Functions;
import com.google.gson.annotations.Expose;

import java.util.List;
import java.util.Vector;
public class FuncParam {
    static final int IN_BIT = 16;
    static final int OUT_BIT = 256;
    @Expose
    List<Integer> inoutTypes;
    @Expose
    List<String> identificators;
    @Expose
    List<String> parametersT;
    @Expose
    int countOfPars;
    public FuncParam() {
        countOfPars = 0;
    }
    public void Init(int numPar) {
        countOfPars = numPar;
        if (numPar != 0) {
            parametersT = new Vector<>(numPar);
            inoutTypes = new Vector<>(numPar);
            identificators = new Vector<>(numPar);
            for (int z = 0; z < numPar; ++z) {
                parametersT.add("NONE_T");
                inoutTypes.add(0);
                identificators.add("");
            }
        }
    }
    boolean IsArgIn(int num) {
        if (num >= countOfPars)
            return false;
        else
            return (inoutTypes.get(num) & IN_BIT) != 0;
    }
    boolean IsArgOut(int num) {
        if (num >= countOfPars)
            return false;
        else
            return (inoutTypes.get(num) & OUT_BIT) != 0;
    }
    boolean IsArgInOut(int num) {
        if (num >= countOfPars)
            return false;
        else
            return IsArgIn(num) && IsArgOut(num);
    }
    public void FillParam(int num, String type, String ident, int inout) {
        parametersT.set(num, type);
        inoutTypes.set(num, inout);
        identificators.set(num, ident);
    }
    @Override
    public String toString() {
        Vector<String> res = new Vector<>();
        for (int i = 0; i < countOfPars; ++i) {
            String ps = IsArgInOut(i) ? "inout" :
                    (IsArgOut(i) ? "out" : (IsArgIn(i) ? "in" : "?!"));
            ps += " " + inoutTypes.get(i) + " " + identificators.get(i) + " " + parametersT.get(i);
            res.add(ps);
        }
        return String.join(",", res);
    }
}
