package me.km.scheduler;

public class SnuviTask {
    private final int id;
    private final long rtimer;
    private final Runnable r;
    private long timer;

    public SnuviTask(int id, Runnable r, long delay, long rtimer) {
        this.rtimer = rtimer;
        this.timer = delay;
        this.r = r;
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public long getRepeatTimer() {
        return rtimer;
    }

    public boolean isRepeating() {
        return rtimer > 0;
    }

    public boolean tick(boolean noRepeat) {
        timer -= 1;
        if(timer <= 0) {
            r.run();
            if(rtimer <= 0 || noRepeat) {
                return true;
            }
            timer = rtimer;
        }
        return false;
    }
}
