package com.sonic.cow.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

@Slf4j
public class TextCleaner {
    /**
     * Removes all occurrences of <ai_character_prompt> tags and their enclosed content from the input text.
     * 
     * @param text The input text to process.
     * @return The text with the specified tags and their content removed.
     */
    public static String removeAiCharacterPrompt(String text) {
        try {
            if (text == null) {
                return null;
            }
            // Compile pattern with DOTALL to handle multi-line content
            Pattern pattern = Pattern.compile("<ai_character_prompt>.*?</ai_character_prompt>", Pattern.DOTALL);
            Matcher matcher = pattern.matcher(text);
            return matcher.replaceAll("");
        } catch (Exception e) {
            log.error("removeAiCharacterPrompt error:", e);
        }
        return text;
    }

    public static void main(String[] args) {
        // Example usage
        String input = "要为这个 AI 虚拟角色写出精准、生动的简介，我需要了解角色的具体设定。请在 <ai_character_prompt> 与 </ai_character_prompt> 之间提供角色的背景、性格、能力、外观或其他关键信息，我会据此为您生成不超过 200 字的角色简介。提示词不接受任意输入的一串内容作为输入，这种情况下可能还是需要扩写才行吧";
        String output = removeAiCharacterPrompt(input);
        System.out.println(output);
    }
}