"""Additional tests for app.services.rule_engine — unknown rule type and default match_mode"""

import pytest


class TestCompileRuleUnknown:
    def test_unknown_rule_type_returns_true(self):
        """Unknown rule type returns lambda that always returns True"""
        from app.services.rule_engine import RuleEngine
        matcher = RuleEngine.compile_rule({"type": "nonexistent"})
        assert matcher({"title": "anything"}) is True


class TestCompileMultiRule:
    def test_empty_rules_returns_true_without_match_mode(self):
        """Compile_multi_rule with empty rules returns lambda a: True"""
        from app.services.rule_engine import RuleEngine
        matcher = RuleEngine.compile_multi_rule([])
        assert matcher({"title": "test"}) is True

    def test_unknown_match_mode_defaults_to_any(self):
        """Unknown match_mode defaults to 'any'"""
        from app.services.rule_engine import RuleEngine
        rules = [{"type": "keyword", "field": "title", "keyword": "cancer"}]
        matcher = RuleEngine.compile_multi_rule(rules, match_mode="unknown")
        assert matcher({"title": "cancer study"}) is True
        assert matcher({"title": "health"}) is False
