#ifndef FZ_AUTHENTICATION_THROTTLED_AUTHENTICATOR_HPP
#define FZ_AUTHENTICATION_THROTTLED_AUTHENTICATOR_HPP

#include <list>

#include "../filezilla/logger/modularized.hpp"
#include "../filezilla/util/options.hpp"
#include "../util/throttler.hpp"

#include "authenticator.hpp"

namespace fz::authentication
{

class throttled_authenticator: public authenticator
{
public:
	using options = util::throttler::options;

	throttled_authenticator(event_loop &loop, authenticator &wrapped, logger_interface &logger, options opts = {});
	~throttled_authenticator() override;

	void authenticate(std::string_view realm, std::string_view name, const methods_list &methods, address_type family, std::string_view ip, event_handler &target, logger::modularized::meta_map meta_for_logging = {}) override;
	void stop_ongoing_authentications(event_handler &target) override;

	void set_options(options opts);

private:
	class worker;

	event_loop &event_loop_;
	authenticator &wrapped_;
	logger::modularized logger_;

	mutable mutex mutex_;

	using workers_t = std::list<worker>;
	workers_t workers_;

	util::throttler throttler_;
};

}

#endif // FZ_AUTHENTICATION_THROTTLED_AUTHENTICATOR_HPP
