"""Cheap keyword-based pre-filter: gates expensive LLM calls."""

from __future__ import annotations

import logging

from agent_samochodowy.extraction.keywords import has_buy_intent, has_sell_intent, has_skup_intent

logger = logging.getLogger(__name__)


def is_part_request(text: str) -> bool:
    """Return True if the post looks like a buying request for a car part.

    Rejects:
    - Vehicle buyout/scrap ads ("skup ciężarówek").
    - Posts with clear selling intent (and no buying intent).
    - Posts with no intent signals at all.
    """
    text_lower = text.lower()

    # Vehicle buyout ads are never part requests
    if has_skup_intent(text_lower):
        logger.debug("Pre-filter: skup/buyout ad, skipping")
        return False

    has_buy = has_buy_intent(text_lower)
    has_sell = has_sell_intent(text_lower)

    # Selling post → not a lead
    if has_sell and not has_buy:
        logger.debug("Pre-filter: selling intent, skipping")
        return False

    # Buying intent → pass to LLM
    if has_buy:
        return True

    # No clear intent → skip (conservative: reduce false positives)
    logger.debug("Pre-filter: no intent signal, skipping")
    return False
