#include <Milestone/Milestone.hpp>

bool Milestone::Achievement::matchesQuery(const std::string &query)
{
    std::string lowerTitle = title;
    std::transform(lowerTitle.begin(), lowerTitle.end(), lowerTitle.begin(),
        [](unsigned char c){ return std::tolower(c); });

    std::string lowerDescription = description;
    std::transform(lowerDescription.begin(), lowerDescription.end(), lowerDescription.begin(),
        [](unsigned char c){ return std::tolower(c); });

    std::string lowerQuery = query;
    std::transform(lowerQuery.begin(), lowerQuery.end(), lowerQuery.begin(),
        [](unsigned char c){ return std::tolower(c); });

    return lowerTitle.find(lowerQuery) != std::string::npos ||
            lowerDescription.find(lowerQuery) != std::string::npos;
}

Milestone::Milestone(Material &todoIcon, Material &doneIcon, std::string label) :
    todoIcon(todoIcon),
    doneIcon(doneIcon),
    label(label)
{}