#include "RecentServers.hpp"

#include <algorithm>

namespace tw::app {

RecentServers::RecentServers()
    : FileAddressList("recent_servers.txt") {
}

const char* RecentServers::name() const {
    return "Recent";
}

void RecentServers::add(const std::string& entry) {
    // Remove if already in list (de-duplicate)
    auto it = std::find(m_entries.begin(), m_entries.end(), entry);
    if(it != m_entries.end()) {
        m_entries.erase(it);
    }

    // Add to front (most recent first)
    m_entries.insert(m_entries.begin(), entry);

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

} // namespace tw::app
