#include "pch.h"

#include "legacy_app_startup_services.h"

#include "app.h"
#include "serializer.h"
#include "settings.h"

namespace pp::panopainter {
namespace {

class LegacyAppStartupServices final : public pp::app::AppStartupServices {
public:
    explicit LegacyAppStartupServices(App& app) noexcept
        : app_(app)
    {
    }

    void store_run_counter(int value) override
    {
        Settings::set("run_counter", Serializer::Integer(value));
        LOG("run_counter %d", value);
    }

    void save_preferences() override
    {
        if (!Settings::save())
            LOG("save preferences failed");
    }

    void start_timelapse_recording() override
    {
        app_.rec_start();
    }

    void apply_vr_controllers_enabled(bool enabled) override
    {
        app_.vr_controllers_enabled = enabled;
    }

    void show_license_warning() override
    {
        app_.message_box("License", "Could not validate this license, running in demo mode.");
    }

private:
    App& app_;
};

} // namespace

pp::foundation::Status execute_legacy_app_startup_plan(
    App& app,
    const pp::app::AppStartupPlan& plan)
{
    LegacyAppStartupServices services(app);
    return pp::app::execute_app_startup_plan(plan, services);
}

pp::foundation::Status execute_legacy_app_startup_persistence_plan(
    App& app,
    const pp::app::AppStartupPlan& plan)
{
    LegacyAppStartupServices services(app);
    return pp::app::execute_app_startup_persistence_plan(plan, services);
}

pp::foundation::Status execute_legacy_app_startup_runtime_plan(
    App& app,
    const pp::app::AppStartupPlan& plan)
{
    LegacyAppStartupServices services(app);
    return pp::app::execute_app_startup_runtime_plan(plan, services);
}

} // namespace pp::panopainter
