#include "fake_hmb_service.h"

auto const null_handler = [](bool){};

repowerd::test::FakeHighBrightnessMode::FakeHighBrightnessMode()
    : event_loop{"FakeHighBrightnessMode"}
    , hbm_handler(null_handler)
    , enabled{false}
    , supported{true}
{
}

void repowerd::test::FakeHighBrightnessMode::set_enabled(bool enabled)
{
    if (this->enabled == enabled)
        return;

    this->enabled = enabled;
    hbm_handler(enabled);
}

bool repowerd::test::FakeHighBrightnessMode::get_enabled()
{
    return enabled;
}

bool repowerd::test::FakeHighBrightnessMode::is_supported() const
{
    return supported;
}

repowerd::HandlerRegistration repowerd::test::FakeHighBrightnessMode::register_high_brightness_mode_handler(
    const HighBrightnessModeHandler &handler)
{
    return EventLoopHandlerRegistration(
        event_loop,
        [this, handler] { hbm_handler = handler;},
        [this] { hbm_handler = null_handler; });
}

void repowerd::test::FakeHighBrightnessMode::set_supported(bool supported)
{
    this->supported = supported;
}

void repowerd::test::FakeHighBrightnessMode::flush_event_loop()
{
    std::promise<void> flushed;
    event_loop.enqueue([&flushed] { flushed.set_value(); });
    flushed.get_future().wait();
}
