#include "softwarefilter.h"

#include <QVariantMap>
#include <regex>

SoftwareFilter::SoftwareFilter(const QJsonObject &obj)
{
    auto filter = obj.toVariantMap();
    nameFilters = filter.value("name_filter_list").toStringList();
    binaryFilters = filter.value("binary_filter_list").toStringList();
    category = filter.value("category").toString();
}

bool SoftwareFilter::matchName(const QString &name) const
{
    for (auto &str : nameFilters) {
        std::regex nameRegEx(str.toStdString());
        if(std::regex_match(name.toStdString(), nameRegEx)) {
            return true;
        }
    }
    return false;
}

bool SoftwareFilter::matchBinary(const QString &binary) const
{
    for (auto &str : binaryFilters) {
        std::regex nameRegEx(str.toStdString());
        if(std::regex_match(binary.toStdString(), nameRegEx)) {
            return true;
        }
    }
    return false;
}
