"""Tests for R-309 extraction prompt v3 improvements in prompts_v2.py."""

from cortex.extraction.prompts_v2 import ALLOWED_PREDICATES, EXTRACTION_SYSTEM_PROMPT


class TestNewPredicates:
    """Verify all 10 new predicates are in ALLOWED_PREDICATES."""

    NEW_PREDICATES = [
        "created", "founded", "built", "values", "believes",
        "experienced", "feels", "completed", "achieved", "runs_on",
    ]

    def test_all_new_predicates_in_allowed_set(self):
        for pred in self.NEW_PREDICATES:
            assert pred in ALLOWED_PREDICATES, f"Missing predicate: {pred}"

    def test_new_predicates_in_prompt_text(self):
        """All 10 new predicates appear in the human-readable predicate list."""
        for pred in self.NEW_PREDICATES:
            assert pred in EXTRACTION_SYSTEM_PROMPT, (
                f"Predicate '{pred}' not found in EXTRACTION_SYSTEM_PROMPT text"
            )


class TestPreserveExactValues:
    """Verify PRESERVE EXACT VALUES guideline is present."""

    def test_preserve_exact_values_header(self):
        assert "PRESERVE EXACT VALUES" in EXTRACTION_SYSTEM_PROMPT

    def test_preserve_exact_values_examples(self):
        assert "$45/month for GO tier" in EXTRACTION_SYSTEM_PROMPT
        assert "Voice ID Iv7T7tshr4OkDgK2zRAo" in EXTRACTION_SYSTEM_PROMPT
        assert "10,000 MAU" in EXTRACTION_SYSTEM_PROMPT


class TestMultiItemSplitting:
    """Verify MULTI-ITEM SPLITTING guideline is present."""

    def test_multi_item_splitting_header(self):
        assert "MULTI-ITEM SPLITTING" in EXTRACTION_SYSTEM_PROMPT

    def test_multi_item_splitting_examples(self):
        assert "one claim per item" in EXTRACTION_SYSTEM_PROMPT
        assert "Three separate claims, one per tier" in EXTRACTION_SYSTEM_PROMPT


class TestIdentityAndCornerstoneContent:
    """Verify IDENTITY AND CORNERSTONE CONTENT guideline is present."""

    def test_identity_cornerstone_header(self):
        assert "IDENTITY AND CORNERSTONE CONTENT" in EXTRACTION_SYSTEM_PROMPT

    def test_identity_cornerstone_guidance(self):
        assert "confidence: 0.95+" in EXTRACTION_SYSTEM_PROMPT
        assert "up to 400" in EXTRACTION_SYSTEM_PROMPT


class TestCharacterLimits:
    """Verify updated character limit guidance."""

    def test_200_char_default(self):
        assert "Target under 200" in EXTRACTION_SYSTEM_PROMPT

    def test_400_char_identity(self):
        assert "400 characters is acceptable" in EXTRACTION_SYSTEM_PROMPT

    def test_category_detail_levels(self):
        assert "Preserve maximum detail, up to 400 chars" in EXTRACTION_SYSTEM_PROMPT
        assert "Include context, up to 300 chars" in EXTRACTION_SYSTEM_PROMPT
        assert "Include reasoning/tradeoffs, up to 300 chars" in EXTRACTION_SYSTEM_PROMPT
        assert "Include temporal + emotional context, up to 250 chars" in EXTRACTION_SYSTEM_PROMPT
        assert "Standard 200 char target" in EXTRACTION_SYSTEM_PROMPT


class TestOriginalPredicatesPreserved:
    """Ensure original predicates still exist."""

    ORIGINAL_PREDICATES = [
        "prefers", "likes", "dislikes", "avoids", "uses", "requires",
        "decides", "chose", "plans", "has", "owns", "manages", "knows",
        "learned", "is", "has_trait", "has_relationship", "lives_in",
        "works_at", "desires", "has_issue", "blocked_by", "needs",
        "recommends", "agrees_with", "understands", "has_role", "describes",
        "acknowledges", "has_agent", "deployed", "proposed", "identified",
        "attended", "participated_in", "identifies", "visited", "started",
        "decided",
    ]

    def test_original_predicates_still_present(self):
        for pred in self.ORIGINAL_PREDICATES:
            assert pred in ALLOWED_PREDICATES, f"Original predicate missing: {pred}"
