package net.cobem.grizzly.habbohotel.roleplay;

import net.cobem.grizzly.communication.composers.rooms.SendRoomWhisperComposer;
import net.cobem.grizzly.habbohotel.effects.EffectType;
import net.cobem.grizzly.habbohotel.sessions.Session;

public class WorkoutMonitor implements Runnable {
    private Thread Thread;

    private int WaitTime = 0;

    private Session User;

    private WorkoutRunMonitor RunMonitor;

    public WorkoutMonitor(Session Session) {
        this.User = Session;

        RunMonitor = new WorkoutRunMonitor(Session);
    }

    @Override
    public void run() {
        while (WaitTime > -1) {
            if (this.WaitTime == 0) {
                User.getRoleplay().upgradeStrength(1);
                User.effect(EffectType.PULSATING_GLOW);
                User.sendResponse(SendRoomWhisperComposer.compose(User.getHabbo().getID(), "You've leveled up to level " + User.getRoleplay().getStrength(), 0));

                this.WaitTime = (User.getRoleplay().getStrength() * 2 - 1); //keep it rolling
            } else {
                User.sendResponse(SendRoomWhisperComposer.compose(User.getHabbo().getID(), "You have " + this.WaitTime + " more minutes till you reach level " + (User.getRoleplay().getStrength() + 1), 0));
                User.effect(0);
                this.WaitTime--;
            }

            try {
                Thread.sleep(60000);
            } catch (InterruptedException ignored) {
            }
        }
    }

    public void start() {
        if (this.WaitTime == 0) {
            this.WaitTime = 2;
        }

        this.Thread = new Thread(this);
        this.Thread.start();

        this.RunMonitor.start();
    }

    public void stop() {
        this.Thread.stop();
        this.RunMonitor.stop();
    }

    public int getWaitTime() {
        return this.WaitTime + 1;
    }

}
