#pragma once

#include <string>

class ProgressMonitor {
public:
	ProgressMonitor() :
			finished(false), running(false), canceled(false), steps(0), currentStep(
					0) {

	}

	bool begin(std::string task, size_t steps) {
		if (canceled)
			return false;
		this->task = task;
		this->steps = steps;
		this->running = true;
		finished = false;
		currentStep = 0;
		return true;
	}

	bool advance(size_t count = 1) {
		currentStep += count;
		return !canceled;
	}

	size_t getSteps() {
		return steps;
	}

	size_t getCurrentStep() {
		return currentStep;
	}

	float getProgress() {
		return float(currentStep) / float(steps);
	}

	void finish() {
		task = "Finished";
		currentStep = 0;
		steps = 0;
		running = false;
		finished = true;
		canceled = false;
	}

	void cancel() {
		canceled = true;
	}

	std::string &getTask() {
		return task;
	}

	bool isFinished() {
		return finished;
	}

	bool isRunning() {
		return running;
	}

	bool isCanceled() {
		return canceled;
	}

protected:
	bool finished;
	bool running;
	bool canceled;
	std::string task;
	size_t steps;
	size_t currentStep;
};
