// Log file parser for verifying navigation
#pragma once

#include <string>
#include <vector>
#include <optional>
#include <filesystem>

namespace mosis::test {

// Represents a parsed log entry
struct LogEntry {
    std::string message;
    std::string timestamp;  // If available
};

class LogParser {
public:
    LogParser() = default;
    explicit LogParser(const std::filesystem::path& logPath);

    // Set the log file path
    void SetLogPath(const std::filesystem::path& path);

    // Reload log file from disk
    bool Reload();

    // Clear cached entries (for fresh start)
    void Clear();

    // Get all entries
    const std::vector<LogEntry>& GetEntries() const { return m_entries; }

    // Search for a pattern in log entries (returns first match or nullopt)
    std::optional<LogEntry> FindEntry(const std::string& pattern) const;

    // Check if pattern exists in log
    bool Contains(const std::string& pattern) const;

    // Get entries matching a pattern
    std::vector<LogEntry> FindAllEntries(const std::string& pattern) const;

    // Wait for a pattern to appear in the log (reloads periodically)
    bool WaitForEntry(const std::string& pattern, int timeoutMs = 5000);

    // Get last N entries
    std::vector<LogEntry> GetLastEntries(size_t count) const;

private:
    std::filesystem::path m_logPath;
    std::vector<LogEntry> m_entries;
    size_t m_lastReadPosition = 0;
};

} // namespace mosis::test
