// SPDX-License-Identifier: Apache-2.0
// Copyright 2025 Wildcard Matcher Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef WILDCARD_MATCHER_H
#define WILDCARD_MATCHER_H

#include <string>
#include <vector>
#include <iostream>

/**
 * @brief A comprehensive wildcard pattern matcher using dynamic programming
 *
 * This class provides functionality to match strings against wildcard patterns
 * containing '?' (matches any single character) and '*' (matches any sequence).
 * Implements both recursive backtracking and dynamic programming approaches.
 */
class WildcardMatcher {
public:
    // Lifecycle
    WildcardMatcher();
    ~WildcardMatcher();

    // Operations
    bool IsMatch(const std::string& text, const std::string& pattern);
    bool IsMatchRecursive(const std::string& text, const std::string& pattern);
    bool IsMatchDP(const std::string& text, const std::string& pattern);
    void PrintMatchResult(const std::string& text, const std::string& pattern, bool result) const;
    void RunTests();

    // Accessors
    int GetRecursionCount() const { return mRecursionCount; }
    int GetBacktrackCount() const { return mBacktrackCount; }
    int GetDPTableSize() const { return mDPTableSize; }

private:
    // Constants
    static const char WILDCARD_SINGLE = '?';
    static const char WILDCARD_MULTI = '*';

    // Attributes
    int mRecursionCount;
    int mBacktrackCount;
    int mDPTableSize;

    // Helper methods
    bool IsMatchRecursiveHelper(const std::string& text, const std::string& pattern, 
                               int textIdx, int patternIdx);
    bool IsValidPattern(const std::string& pattern) const;
    std::string PreprocessPattern(const std::string& pattern) const;
    void ResetCounters();
    void PrintDebugInfo(const std::string& text, const std::string& pattern, 
                       int textIdx, int patternIdx, const std::string& action) const;
};

#endif // WILDCARD_MATCHER_H