#ifndef LDASTOOLSAL__PATTERN_MATCHER_HH
#define LDASTOOLSAL__PATTERN_MATCHER_HH

#include <string>
#include <vector>
#include <regex>
#include <unordered_map>
#include <mutex>

namespace LDASTools {
namespace AL {

/// @brief Utility class for matching logger channel patterns
class PatternMatcher {
public:
    /// @brief Check if a pattern matches a channel name
    /// @param pattern Pattern with wildcards (e.g., "framecpp.*", "*.frtoc", "framecpp.fr*")
    /// @param channel Channel name to test (e.g., "framecpp.frtoc")
    /// @return True if the pattern matches the channel
    static bool matches(const std::string& pattern, const std::string& channel);

    /// @brief Find all channels matching a pattern
    /// @param pattern Pattern to match
    /// @param all_channels List of all available channels
    /// @return Vector of matching channel names
    static std::vector<std::string> find_matching_channels(
        const std::string& pattern,
        const std::vector<std::string>& all_channels);

    /// @brief Check if a pattern is a prefix match
    /// @param pattern Pattern to check
    /// @param channel Channel name to test
    /// @return True if pattern is a prefix of channel
    static bool is_prefix_match(const std::string& pattern, const std::string& channel);

    /// @brief Check if a pattern is an exact match
    /// @param pattern Pattern to check  
    /// @param channel Channel name to test
    /// @return True if pattern exactly matches channel
    static bool is_exact_match(const std::string& pattern, const std::string& channel);

private:
    /// @brief Convert wildcard pattern to regex
    /// @param pattern Pattern with wildcards (* and ?)
    /// @return Regex string
    static std::string pattern_to_regex(const std::string& pattern);

    /// @brief Cache for compiled regex patterns
    static std::unordered_map<std::string, std::regex> regex_cache_;
    static std::mutex cache_mutex_;

    /// @brief Get or compile a regex for a pattern
    /// @param pattern Wildcard pattern
    /// @return Reference to compiled regex
    static const std::regex& get_regex(const std::string& pattern);
};

} // namespace AL
} // namespace LDASTools

#endif // LDASTOOLSAL__PATTERN_MATCHER_HH