#include "mining_pool_panel.h"

#include <algorithm>

namespace dragonx {
namespace ui {

bool shouldDefaultPoolWorker(const std::string& currentWorker, bool alreadyDefaulted)
{
    return !alreadyDefaulted && (currentWorker.empty() || currentWorker == "x");
}

std::string defaultPoolWorkerAddress(const std::vector<AddressInfo>& addresses)
{
    for (const auto& addr : addresses) {
        if (addr.type == "shielded" && !addr.address.empty()) {
            return addr.address;
        }
    }
    return {};
}

std::string resolveMiningUserAddress(const std::string& payoutAddress,
                                     const std::string& firstShieldedAddress,
                                     const std::string& firstTransparentAddress)
{
    // The configured payout address is the pool login rewards go to, so it wins over
    // the wallet's own addresses. "x" is the placeholder for an unset field.
    if (!payoutAddress.empty() && payoutAddress != "x") return payoutAddress;
    if (!firstShieldedAddress.empty()) return firstShieldedAddress;
    return firstTransparentAddress;  // may be empty -> caller reports "no address"
}

bool miningValueAlreadySaved(const std::vector<std::string>& savedValues,
                             const std::string& value)
{
    if (value.empty()) return false;
    return std::find(savedValues.begin(), savedValues.end(), value) != savedValues.end();
}

const char* defaultPoolUrl()
{
    return "pool.dragonx.is:3433";
}

} // namespace ui
} // namespace dragonx
