"""Tests for the regex-based fallback extractor."""

from datetime import datetime

from agent_samochodowy.extraction.regex_extractor import extract_with_regex
from agent_samochodowy.models import Post


def _post(text: str) -> Post:
    return Post(
        post_id="1",
        group="test",
        author_name="Test",
        author_profile_url="https://fb.com/test",
        text=text,
        timestamp=datetime(2025, 1, 1),
        post_url="https://fb.com/posts/1",
    )


class TestRegexExtractor:
    def test_extracts_brand(self):
        q = extract_with_regex(_post("Szukam pompy do Volvo FH13"))
        assert q.brand == "VOLVO"

    def test_extracts_brand_colloquial(self):
        q = extract_with_regex(_post("Szukam alternatora do strucli"))
        assert q.brand == "OPEL"

    def test_extracts_category(self):
        q = extract_with_regex(_post("Szukam alternatora MAN TGA"))
        assert q.category == "alternator"

    def test_extracts_oe_numbers(self):
        q = extract_with_regex(_post("Szukam pompy 20744939 lub 20734268"))
        assert "20744939" in q.oe_numbers
        assert "20734268" in q.oe_numbers

    def test_extracts_engine_code(self):
        q = extract_with_regex(_post("Szukam alternator C18NZ Opel"))
        assert q.engine_code == "C18NZ"

    def test_no_buy_intent(self):
        q = extract_with_regex(_post("Sprzedam pompę wody Volvo"))
        assert q.is_part_request is False

    def test_buy_intent(self):
        q = extract_with_regex(_post("Kupię klocki hamulcowe MAN TGA"))
        assert q.is_part_request is True
        assert q.category == "klocki hamulcowe"
