#include <ISXDK.h>
#include <thread>
#include <argh/argh.h>

#include "ISXMr.h"
#include "Logger.h"
#include "Tasks/BotTask.h"
#include "Tasks/ExportAbilitiesTask.h"
#include "isxeq2/ExtensionTLOs.h"

TaskTypeEnum GetTaskType(const std::string &command)
{
	if (command == "export" || command == "e")
	{
		return TaskTypeEnum::Export;
	}
	if (command == "test" || command == "t")
	{
		return TaskTypeEnum::Test;
	}
	if (command == "bot" || command == "b")
	{
		return TaskTypeEnum::Bot;
	}
	return TaskTypeEnum::NotDefined;
}

int CMD_Mr(int argc, char *argv[])
{
	const argh::parser cmdl(argv);
	const auto taskType = GetTaskType(cmdl[1]);

	if (executor.IsTaskTypeRunning(taskType))
	{
		logw << "Task of type " << cmdl[1] << " is already running" << std::endl;
		return 0;
	}

	switch (taskType)
	{
	case TaskTypeEnum::Export:
		executor.AddTask(std::make_shared<ExportAbilitiesTask>());
		break;
	case TaskTypeEnum::Bot:
		executor.AddTask(BotTask::Instance());
		break;
	case TaskTypeEnum::Test:
		// const auto target = ExtensionTLOs::Actor().GetActorById(ExtensionTLOs::Me().Target().Id());
		log << LogLevel::Info << "Test command" << std::endl;
		break;
	default:
		logw << "USAGE: mr [e|export]: Export abilities\n"
			 << "       mr [b|bot]: Run the combat bot" << std::endl;
		break;
	}

	// if (cmdl[{"-e", "--export"}]) {
	// 	executor.AddTask(std::make_shared<ExportCommand>());
	// } else {
	// 	logger << "USAGE: mr [e|export]: Export abilities" << std::endl;
	// }
	return 0;
}
