/* Copyright 2020, Michele Santullo
 * This file is part of orotool.
 *
 * Orotool is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Orotool is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Orotool.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "oro/api.hpp"
#include "nap/quick_rest.hpp"
#include <mutex>

namespace oro {

class ApiNap : public Api {
public:
	ApiNap (
		std::string&& root_address,
		std::string&& api_key,
		std::string&& client_name,
		std::string&& client_purpose
	);

	virtual ~ApiNap() noexcept;

	virtual ApiOutput<Ping> ping(bool with_raw) override;
	virtual ApiOutput<WhoAmI> who_am_i(bool with_raw) override;
	virtual ApiOutput<Items> items_list(bool with_raw) override;
	virtual ApiOutput<Icons> items_icons(bool with_raw) override;
	virtual ApiOutput<Shops> market_list(bool with_raw) override;
	virtual ApiOutput<Creators> fame_list(bool with_raw) override;

private:
	template <typename T, typename F>
	ApiOutput<T> fetch_and_parse (const char* endpoint, F&& data_fill, bool with_raw);

	std::mutex m_json_mutex;
	simdjson::dom::parser m_json;
	nap::QuickRest m_qrest;
};

} //namespace oro
