#include "./cancel_request.hpp"

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

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

    void CancelRequest::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
    {
        spdlog::debug("CancelRequestProvider: Providing response for method {}", notification.method);

        auto params = transform::As<protocol::CancelParams>(notification.params.value());
        std::string id_to_cancel = transform::debug::GetIdString(params.id);
        spdlog::info("Processing cancel request for ID: {}", id_to_cancel);

        auto& scheduler = context.GetScheduler();
        bool cancelled = scheduler.Cancel(id_to_cancel);
        spdlog::info("Cancel request {} result: {}", id_to_cancel, cancelled ? "success" : "not found");
    }
}
