package com.red.circle.common.business.core;

import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 敏感词汇筛选
 */
@Component
public class SensitiveWordFilter {

  private static final Logger log = LoggerFactory.getLogger(SensitiveWordFilter.class);

  public static List<String> replaceList = Arrays.asList("7星","七星","ساتستارے","سبعةنجوم","সাততারা","सातसितारे","SEVENSTAR","7STAR","TUJUHBINTANG","7star","sevenstar","tujuhbintang","SEVEN星","七STAR", "MANAGER", "IFUN");
  // 初始化敏感词字典
//  public SensitiveWordFilter() {
//    ResourceLoader resourceLoader = new DefaultResourceLoader();
//    Resource resource = resourceLoader.getResource("classpath:static/SensitiveWord.text");
//
//    try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
//      replaceList = reader.lines() // 读取文件的每一行
//          .map(String::trim) // 去除每行两端的空白字符
//          .filter(line -> !line.isEmpty()) // 过滤掉空行
//          .collect(Collectors.toList()); // 收集到一个列表中
//    } catch (IOException e) {
//      throw new RuntimeException("Failed to load sensitive words", e);
//    }
//  }

  // 检查输入是否包含敏感词
  public static boolean checkSensitiveWord(String input) {
    input = StringUtils.deleteWhitespace(input);
    input=input.replaceAll("[!#@$%^&*()_+=<>?/:;{}\\|,.。\\-~]+", "").toUpperCase();
    for (String replace : replaceList) {
      if (input.contains(replace)) {
        return true;
      }
    }
    return false;
  }

}
