#include "../logger.hpp"
#include <filesystem>
#include "mime.hpp"
#include <unordered_map>

namespace Http
{
	/* Existing MIME types
		text
		image
		audio
		video
		application
		multipart
	*/

	std::string GetMimeType(std::string const & filePath)
	{
		static std::unordered_map<std::string, FileType> fileExtensionMap
		{
			{".html", FileType::HTML},
			{".htm", FileType::HTML},
			{".css", FileType::CSS},
			{".js", FileType::JS},
			{".jpg", FileType::JPG},
			{".jpeg", FileType::JPG},
			{".png", FileType::PNG},
			{".mp3", FileType::MP3},
			{".mp4", FileType::MP4},
		};
		
		std::string const extension = std::filesystem::path(filePath).extension();
		auto const findResult = fileExtensionMap.find(extension);
		if (findResult == fileExtensionMap.end())
		{
			return GetMimeType(FileType::UNKNOWN);
		}

		return GetMimeType(findResult->second); 
	}

	std::string GetMimeType(FileType const fileType)
	{
		switch(fileType)
		{
			default:
			case FileType::UNKNOWN:
			return "text/plain";

			case FileType::HTML:
			return "text/html";

			case FileType::CSS:
			return "text/css";

			case FileType::JS:
			return "application/javascript";

			case FileType::JPG:
			return "image/jpeg";

			case FileType::PNG:
			return "image/png";

			case FileType::MP3:
			return "audio/mpeg3";

			case FileType::MP4:
			return "video/mp4";
		}
	}
}