package me.km.snuviscript.commands;

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

public class TableCommands {
    public static void registerFunctions(ScriptManager sm) {
        sm.registerFunction("table.getstart", (sc, in) -> {
            return TableUtils.getTableStart(in[0].getInt(sc), in[1].getInt(sc), in[2].getString(sc));
        });
        sm.registerFunction("table.getmiddle", (sc, in) -> {
            return TableUtils.getTableMiddle(in[0].getInt(sc), in[1].getInt(sc), in[2].getString(sc));
        });
        sm.registerFunction("table.getend", (sc, in) -> {
            return TableUtils.getTableEnd(in[0].getInt(sc), in[1].getInt(sc), in[2].getString(sc));
        });
        sm.registerFunction("table.get", (sc, in) -> {
            String[] columns = new String[in.length - 2];
            for(int i = 0; i < columns.length; i++) {
                columns[i] = in[i + 2].getString(sc);
            }
            return TableUtils.getTable(in[0].getInt(sc), in[1].getString(sc), columns);
        });
    }
}
