package me.km.snuviscript.commands;

import me.hammerle.snuviscript.code.ScriptManager;
import me.km.utils.Table;

public class TableCommands {
    public static void registerFunctions(ScriptManager sm) {
        sm.registerFunction("table.new", (sc, in) -> {
            int[] widths = new int[in.length - 1];
            for(int i = 0; i < widths.length; i++) {
                widths[i] = in[i + 1].getInt(sc);
            }
            return new Table(in[0].getString(sc), widths);
        });
        sm.registerFunction("table.getstart", (sc, in) -> {
            return ((Table) in[0].get(sc)).getStart();
        });
        sm.registerFunction("table.getmiddle", (sc, in) -> {
            return ((Table) in[0].get(sc)).getMiddle();
        });
        sm.registerFunction("table.getend", (sc, in) -> {
            return ((Table) in[0].get(sc)).getEnd();
        });
        sm.registerFunction("table.get", (sc, in) -> {
            String[] columns = new String[in.length - 1];
            for(int i = 0; i < columns.length; i++) {
                columns[i] = in[i + 1].getString(sc);
            }
            return ((Table) in[0].get(sc)).get(columns);
        });
    }
}
