package com.honey.honey.util;

import java.util.regex.Pattern;

/**
 * Redacts Telegram Bot API token from strings before logging.
 * Token appears in URLs like https://api.telegram.org/bot123456:AAHxxx.../methodName
 */
public final class TelegramTokenRedactor {

    private static final Pattern BOT_TOKEN_IN_URL = Pattern.compile("(/bot)([^/]+)(/)");

    private TelegramTokenRedactor() {
    }

    /**
     * Replaces the bot token in Telegram API URLs with a redaction placeholder.
     * Safe to call with null (returns null).
     */
    public static String redact(String message) {
        if (message == null || message.isEmpty()) {
            return message;
        }
        return BOT_TOKEN_IN_URL.matcher(message).replaceAll("$1***REDACTED***$3");
    }
}
