#include <vector>
#include <chrono>

#include "api.h"
#include "result.h"
#include "lexer.h"
#include "parser.h"
#include "time.h"
#include "config.h"

bool debug;
std::chrono::high_resolution_clock::time_point start;
std::chrono::high_resolution_clock::time_point end;

Result<std::vector<Question*>> Transpile(std::string fileContent, bool isDebug) {
	start = std::chrono::high_resolution_clock::now();
	end = std::chrono::high_resolution_clock::now();
	debug = isDebug;

	auto lexRes = TokenizeMdem(fileContent);
	auto tokens = lexRes.value;
	if (lexRes.error.length() > 0) {
		return {
			{},
			std::format(
				"Lexical analysis error: {}",
				lexRes.error
			),
			lexRes.row,
			lexRes.column
		};
	}

	auto parseRes = ParseQuestions(tokens);
	auto questions = parseRes.value;
	if (parseRes.error.length() > 0) {
		return {
			{},
			std::format(
				"Parsing error: {}",
				parseRes.error
			),
			parseRes.row,
			parseRes.column
		};
	}

	end = std::chrono::high_resolution_clock::now();
	ShowTime("Transpilation time");
	return {questions};
}
