#pragma once
#include <string>

#include "Core/Models.h"
#include "Core/RuntimeSession.h"
#include "Memory/VmmAccessor.h"
#include "Resolvers/LocalPlayerResolver.h"
#include "Resolvers/NetworkMetadataReader.h"

// -------------------------------------------------------------------------
// BaseObjectResolver
// Entry-point resolver that:
//   - validates the game base address
//   - resolves worldAddress and networkManagerAddress
//   - constructs a RuntimeSession
//   - delegates to NetworkMetadataReader and LocalPlayerResolver
// -------------------------------------------------------------------------

class BaseObjectResolver {
public:
    /// Build a fresh RuntimeSession and populate metadata and player data.
    /// Returns true only when all sub-resolvers succeed.
    bool TryResolve(VmmAccessor&     mem,
                    uint32_t         pid,
                    uint64_t         gameBase,
                    RuntimeSession&  session,
                    NetworkMetadata& metadata,
                    LocalPlayerData& player);

    /// Validate that the currently-cached session is still coherent
    /// (world pointer and network manager address have not changed).
    bool IsStillValid(VmmAccessor& mem, const RuntimeSession& session);

    [[nodiscard]] const std::string& LastFailureReason() const noexcept {
        return m_lastFailureReason;
    }

private:
    NetworkMetadataReader m_networkMetadataReader;
    LocalPlayerResolver   m_localPlayerResolver;
    std::string           m_lastFailureReason;
};
