#include "dhcp_configuration.hpp"

#include "config_parser.hpp"
#include "network_manager.hpp"
#include "system_queries.hpp"
#include "util.hpp"

#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>

namespace phosphor
{
namespace network
{
namespace dhcp
{

using namespace phosphor::network;
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;

Configuration::Configuration(sdbusplus::bus_t& bus,
                             stdplus::const_zstring objPath, Manager& parent) :
    Iface(bus, objPath.c_str(), Iface::action::defer_emit),
    bus(bus), manager(parent)
{
    config::Parser conf;
    {
        auto interfaceStrList = system::getInterfaces();
        if (!interfaceStrList.empty())
        {
            conf.setFile(config::pathForIntfConf(manager.getConfDir(),
                                                 *interfaceStrList.begin()));
        }
    }

    ConfigIntf::dnsEnabled(getDHCPProp(conf, "UseDNS"));
    ConfigIntf::ntpEnabled(getDHCPProp(conf, "UseNTP"));
    ConfigIntf::hostNameEnabled(getDHCPProp(conf, "UseHostname"));
    ConfigIntf::sendHostNameEnabled(getDHCPProp(conf, "SendHostname"));
    emit_object_added();
}

bool Configuration::sendHostNameEnabled(bool value)
{
    if (value == sendHostNameEnabled())
    {
        return value;
    }

    auto name = ConfigIntf::sendHostNameEnabled(value);

    manager.writeToConfigurationFile();
    manager.reloadConfigs();

    return name;
}

bool Configuration::hostNameEnabled(bool value)
{
    if (value == hostNameEnabled())
    {
        return value;
    }

    auto name = ConfigIntf::hostNameEnabled(value);
    manager.writeToConfigurationFile();
    manager.reloadConfigs();

    return name;
}

bool Configuration::ntpEnabled(bool value)
{
    if (value == ntpEnabled())
    {
        return value;
    }

    auto ntp = ConfigIntf::ntpEnabled(value);
    manager.writeToConfigurationFile();
    manager.reloadConfigs();

    return ntp;
}

bool Configuration::dnsEnabled(bool value)
{
    if (value == dnsEnabled())
    {
        return value;
    }

    auto dns = ConfigIntf::dnsEnabled(value);
    manager.writeToConfigurationFile();
    manager.reloadConfigs();

    return dns;
}

} // namespace dhcp
} // namespace network
} // namespace phosphor
