#include <softbus_edge/egress/ShadowChannelStore.h>

#include <cmath>

namespace softbus::edge {

bool ShadowChannelStore::write(const softbus::registry::PointTableEntry& entry,
                               double engineeringValue)
{
    channels_[entry.physicalChannel] = engineeringValue;
    return true;
}

std::optional<double> ShadowChannelStore::read(const std::string& physicalChannel) const
{
    const auto it = channels_.find(physicalChannel);
    if (it == channels_.end()) {
        return std::nullopt;
    }
    return it->second;
}

int ShadowChannelStore::rawRegisterValue(const softbus::registry::PointTableEntry& entry,
                                         double engineeringValue) const
{
    if (entry.scale <= 0.0) {
        return static_cast<int>(std::lround(engineeringValue));
    }
    return static_cast<int>(std::lround(engineeringValue / entry.scale));
}

} // namespace softbus::edge
