#include "./exit_provider.hpp"

namespace lsp::providers::exit
{

    std::string ExitProvider::GetMethod() const
    {
        return "exit";
    }

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

    void ExitProvider::HandleNotification(const protocol::NotificationMessage& notification, ProviderContext& context)
    {
        // static_cast<void>(context);
        spdlog::debug("ExitProvider: Providing response for method {}", notification.method);
        spdlog::info("Exit notification received");

        // 触发生命周期事件
        context.TriggerLifecycleEvent(ServerLifecycleEvent::kShuttingDown);

        // 给一些时间完成清理
        std::this_thread::sleep_for(std::chrono::milliseconds(100));

        context.TriggerLifecycleEvent(ServerLifecycleEvent::kShutdown);

        std::exit(0);
    }

}
