#include "command_line.hpp"
#include "nt.hpp"

#include <shellapi.h>
#include <winrt/Windows.Foundation.h>

namespace utils::command_line
{
	template <typename type, typename deleter>
	constexpr std::unique_ptr<type, deleter> make_unique_ptr(type* ptr, deleter&& del)
	{
		return std::unique_ptr<type, deleter&&>(ptr, std::forward<deleter>(del));
	}

	const std::vector<std::filesystem::path>& get_args()
	{
		static const auto args = []()
		{
			auto argc = 0;
			const auto cmd_line = winrt::check_pointer(::GetCommandLineW());
			const auto up = make_unique_ptr(winrt::check_pointer(::CommandLineToArgvW(cmd_line, &argc)), ::LocalFree);
			const auto argv = up.get();

			std::vector<std::filesystem::path> vec(argc);
			std::transform(argv, argv + argc, vec.begin(), [](const auto* path)
			{
				return std::filesystem::path(path);
			});

			return vec;
		}();

		return args;
	}
}
