#pragma once
// ── CS2 External C++ WebRadar — Game Process ────────────────────────────────
// Manages the CS2 process handle and client.dll module.
// Matches C# GameProcess.cs: finds "cs2" process, loads "client.dll" module,
// checks window foreground state. Runs on a background thread.

#include "game/threaded_service.h"
#include "core/module.h"
#include <windows.h>

class GameProcess : public ThreadedServiceBase {
public:
    static constexpr const wchar_t* PROCESS_NAME  = L"cs2.exe";
    static constexpr const wchar_t* MODULE_NAME   = L"client.dll";
    static constexpr const wchar_t* WINDOW_TITLE  = L"Counter-Strike 2";

    GameProcess();
    ~GameProcess() override;

    HANDLE handle() const { return m_handle; }
    const Module& client_module() const { return m_client_module; }
    std::uintptr_t client_base() const { return m_client_module.base; }
    bool is_valid() const { return m_valid; }
    HWND window() const { return m_window; }

protected:
    void frame_action() override;

private:
    HANDLE  m_handle = nullptr;
    Module  m_client_module;
    HWND    m_window = nullptr;
    DWORD   m_pid = 0;
    bool    m_valid = false;

    bool ensure_process();
    bool ensure_module();
    bool ensure_window();
    void invalidate();
};
