extends Node

var tasks = {}
onready var ConsoleService = $"/root/ConsoleService"

signal task_start;
signal task_complete

func start(name: String, message: String):
	var task = Task.new(name, message)
	if not tasks.has(task.name): tasks[task.name] = []
	tasks[task.name].append(task)
	emit_signal('task_start', task)
	ConsoleService.log("[TaskService] Started: "+name)
	
func complete(name: String):
	if not tasks[name]: return
	var task = tasks[name].pop_front()
	if tasks[name].size() == 0:
		tasks.erase(name)
	emit_signal('task_complete', task)
	ConsoleService.log("[TaskService] Completed: "+name)

class Task:
	var name = ''
	var message = ''

	func _init(_name: String, _message: String):
		name = _name
		message = _message
