/*
 * Mirai. Copyright (C) 2024 Vyn
 * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
 * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
 */

#pragma once

#include <cctype>
#include <cpp-utils/string.h>
#include <cpp-utils/vector.h>
#include <functional>
#include <optional>

namespace mirai
{
namespace stringUtils = cpputils::string;
namespace vectorUtils = cpputils::vector;

bool isDate(const std::string &dateStr);

template <typename T, typename F> T *ptrFindFirst(std::vector<T> &container, F f)
{
	auto element = std::ranges::find_if(container, f);
	if (element == container.end()) {
		return nullptr;
	}
	return &(*element);
}

// TODO use ref for container first arg
template <typename T, typename F> std::optional<T> findFirst(std::vector<T> container, F f)
{
	auto element = std::ranges::find_if(container, f);
	if (element == container.end()) {
		return std::nullopt;
	}
	return *element;
}

template <typename T, typename F> std::vector<T> findAll(std::vector<T> container, F f)
{
	std::vector<T> result;
	std::ranges::copy_if(container, std::back_inserter(result), f);
	return result;
}

int generateUniqueId();

} // namespace mirai
