"""
禁忌过滤 - 过滤不合适的礼物
"""
from typing import List, Dict

class GiftFilter:
    """礼物禁忌过滤器"""

    # 禁忌库
    TABOOS = {
        "钟": ["送终", "谐音不吉利"],
        "鞋": ["送邪", "谐音不吉利"],
        "梨": ["分离", "谐音不吉利"],
        "伞": ["散", "谐音不吉利"],
        "蜡烛": ["祭祀", "不吉利"],
        "手帕": ["分手", "寓意不好"],
    }

    # 关系特殊禁忌
    RELATION_TABOOS = {
        "情侣": ["伞", "梨", "手帕"],  # 怕分离
        "病人": ["钟", "蜡烛"],  # 不吉利
        "长辈": ["钟", "蜡烛"],  # 不吉利
    }

    def filter(self, gifts: List[Dict], relation: str = None) -> List[Dict]:
        """
        过滤禁忌礼物

        Args:
            gifts: 礼物列表
            relation: 收礼人关系

        Returns:
            过滤后的礼物列表
        """
        filtered = []

        for gift in gifts:
            name = gift.get("name", "")

            # 检查通用禁忌
            is_taboo = False
            for taboo_word, reasons in self.TABOOS.items():
                if taboo_word in name:
                    is_taboo = True
                    break

            # 检查关系特殊禁忌
            if relation and not is_taboo:
                for rel_key, taboo_words in self.RELATION_TABOOS.items():
                    if rel_key in relation:
                        for taboo_word in taboo_words:
                            if taboo_word in name:
                                is_taboo = True
                                break
                        if is_taboo:
                            break

            if not is_taboo:
                filtered.append(gift)

        return filtered
