#include <spdlog/spdlog.h>
#include "./set_trace.hpp"
#include "../../protocol/transform/facade.hpp"

namespace lsp::provider
{
    std::string SetTrace::GetMethod() const
    {
        return "$/setTrace";
    }

    std::string SetTrace::GetProviderName() const
    {
        return "SetTrace";
    }

    void SetTrace::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
    {
        static_cast<void>(context);
        spdlog::debug("SetTraceProvider: Providing response for method {}", notification.method);

        protocol::SetTraceParams params = transform::As<protocol::SetTraceParams>(notification.params.value());
        if (params.value == protocol::TraceValueLiterals::Off)
        {
            spdlog::set_level(spdlog::level::info);
            spdlog::info("SetTrace: Tacing disabled");
        }
        else if (params.value == protocol::TraceValueLiterals::Messages)
        {
            spdlog::set_level(spdlog::level::debug);
            spdlog::info("SetTrace: Tacing enabled (message only)");
        }
        else if (params.value == protocol::TraceValueLiterals::Verbose)
        {
            spdlog::set_level(spdlog::level::trace);
            spdlog::info("SetTrace: Tacing enabled (verbose)");
        }
    }

}
