#include "FavouriteServers.hpp"

#include <algorithm>

namespace tw::app {

FavouriteServers::FavouriteServers()
    : FileAddressList("favourite_servers.txt") {
}

const char* FavouriteServers::name() const {
    return "Favourites";
}

void FavouriteServers::add(const std::string& entry) {
    // Check if already present
    auto it = std::find(m_entries.begin(), m_entries.end(), entry);
    if(it != m_entries.end()) {
        return; // Already present, do nothing
    }

    // Append at the end
    m_entries.push_back(entry);

    // Cap at MAX_ENTRIES
    if(m_entries.size() > MAX_ENTRIES) {
        m_entries.resize(MAX_ENTRIES);
    }
}

} // namespace tw::app
