package com.petshop.backend.util;

import com.petshop.backend.exception.BusinessException;

import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;

public class ContentFilter {

    private static final Pattern SCRIPT_PATTERN = Pattern.compile(
            "<script|javascript:|on\\w+\\s*=", Pattern.CASE_INSENSITIVE);

    private static final Set<String> PROFANITY = Set.of(
            "profanityOne", "profanityTwo", "profanityThree"
    );

    public static void validate(String input) {
        if (input == null || input.isBlank()) return;
        if (SCRIPT_PATTERN.matcher(input).find()) {
            throw new BusinessException("Message contains prohibited content");
        }
        String lower = input.toLowerCase(Locale.ROOT);
        for (String word : PROFANITY) {
            if (lower.contains(word)) {
                throw new BusinessException("Message contains prohibited language");
            }
        }
    }
}
