#include "fan_speed.hpp"

#include "env.hpp"
#include "hwmon.hpp"
#include "hwmonio.hpp"
#include "sensorset.hpp"
#include "sysfs.hpp"

#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Control/Device/error.hpp>

#include <format>

using namespace phosphor::logging;

namespace hwmon
{

uint64_t FanSpeed::target(uint64_t value)
{
    try
    {
        _ioAccess->write(value, _type, _id, entry::target, hwmonio::retries,
                         hwmonio::delay);
    }
    catch (const std::system_error& e)
    {
        using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error;
        report<WriteFailure>(
            xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO(
                e.code().value()),
            xyz::openbmc_project::Control::Device::WriteFailure::
                CALLOUT_DEVICE_PATH(_devPath.c_str()));

        auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
                                           entry::target);

        log<level::INFO>(std::format("Failing sysfs file: {} errno: {}", file,
                                     e.code().value())
                             .c_str());

        exit(EXIT_FAILURE);
    }

    return FanSpeedObject::target(value);
}

void FanSpeed::enable()
{
    auto enable = env::getEnv("ENABLE", _type, _id);
    if (!enable.empty())
    {
        auto val = std::stoul(enable);

        try
        {
            _ioAccess->write(val, type::pwm, _id, entry::enable,
                             hwmonio::retries, hwmonio::delay);
        }
        catch (const std::system_error& e)
        {
            using namespace sdbusplus::xyz::openbmc_project::Control::Device::
                Error;
            phosphor::logging::report<WriteFailure>(
                xyz::openbmc_project::Control::Device::WriteFailure::
                    CALLOUT_ERRNO(e.code().value()),
                xyz::openbmc_project::Control::Device::WriteFailure::
                    CALLOUT_DEVICE_PATH(_devPath.c_str()));

            auto fullPath = sysfs::make_sysfs_path(_ioAccess->path(), type::pwm,
                                                   _id, entry::enable);

            log<level::INFO>(std::format("Failing sysfs file: {} errno: {}",
                                         fullPath, e.code().value())
                                 .c_str());

            exit(EXIT_FAILURE);
        }
    }
}

} // namespace hwmon
