#pragma once

#include <string>
#include <vector>
#include <regex>
#include <nlohmann/json.hpp>

namespace simple_object_storage {

class InputValidator {
public:
    // Maximum lengths for various inputs
    static constexpr size_t MAX_LABEL_LENGTH = 255;
    static constexpr size_t MAX_TAG_LENGTH = 255;
    static constexpr size_t MAX_LABELTAG_LENGTH = 512;  // label:tag combined
    static constexpr size_t MAX_METADATA_SIZE = 1024 * 1024;  // 1MB for metadata JSON
    static constexpr size_t MAX_HASH_LENGTH = 64;  // SHA-256 hex string
    static constexpr size_t MAX_FILENAME_LENGTH = 255;
    static constexpr size_t MAX_JSON_FIELD_LENGTH = 4096;
    static constexpr size_t MAX_LABELTAGS_COUNT = 100;  // Max number of label:tags per object
    
    // Validation result structure
    struct ValidationResult {
        bool valid;
        std::string error;
        
        ValidationResult(bool v = true, const std::string& e = "") : valid(v), error(e) {}
    };
    
    // Validate a single label:tag pair
    static ValidationResult validateLabelTag(const std::string& labeltag);
    
    // Validate a label component
    static ValidationResult validateLabel(const std::string& label);
    
    // Validate a tag component
    static ValidationResult validateTag(const std::string& tag);
    
    // Validate a list of label:tag pairs
    static ValidationResult validateLabelTags(const std::vector<std::string>& labeltags);
    
    // Validate a SHA-256 hash
    static ValidationResult validateHash(const std::string& hash);
    
    // Validate metadata JSON
    static ValidationResult validateMetadata(const nlohmann::json& metadata);
    
    // Validate a filename
    static ValidationResult validateFilename(const std::string& filename);
    
    // Check if a string contains only allowed characters for labels/tags
    static bool isValidLabelTagCharset(const std::string& str);
    
    // Check if a string is a valid JSON field name
    static bool isValidJsonFieldName(const std::string& fieldName);
    
private:
    // Regex patterns for validation
    static const std::regex LABEL_TAG_PATTERN;
    static const std::regex LABEL_PATTERN;
    static const std::regex TAG_PATTERN;
    static const std::regex HASH_PATTERN;
    static const std::regex JSON_FIELD_PATTERN;
};

} // namespace simple_object_storage