"""wants_external_entity_ingest / wants_external_content_ingest: the
three-group semantic matcher (external source x inbound action x
entity/content target) for the external.entity_ingest primitive.

Deliberately not a BlockRule in select_capabilities -- see planner.py's
comment on why (frozen App Block catalog allowlist).
"""
from __future__ import annotations

import pytest

from src.domain.app_blocks.planner import (
    wants_external_content_ingest,
    wants_external_entity_ingest,
)

CONTENT_POSITIVES = [
    "Sync Airtable articles into my blog.",
    "Let Make.com send posts into this site.",
    "Receive CMS entries from n8n.",
    "Push articles into my website through a webhook.",
    "Create or update content from an external automation.",
    "Import resources from another system.",
    "Import posts from Airtable",
    "Send blog entries from Make",
    "Webhook new articles into the site",
    "Keep my CMS content synced",
]

GENERIC_ONLY_POSITIVES = [
    "Push listings from my backend into the app.",
    "Ingest listings from our ERP",
    "Upsert products from n8n",
    "Receive records from an external system",
    "Populate the directory from a webhook",
    "Push products from our ERP into the app",
]

# Outbound automation, or automation unrelated to entity mutation. Must not
# match even though each contains a source word and/or an action-shaped verb.
NEGATIVES = [
    "Trigger a Make.com scenario when an order ships.",
    "Send a webhook to n8n when a booking is cancelled.",
    "I need a contact form on my site.",
    "trigger Make.com when a post is created",
    "send form submissions to n8n",
    "call a webhook after checkout",
    "notify Zapier when an order changes",
    "send an email using Make.com",
]


@pytest.mark.parametrize("text", CONTENT_POSITIVES)
def test_content_shaped_ingestion_prompts_match_both(text: str) -> None:
    assert wants_external_entity_ingest(text) is True
    assert wants_external_content_ingest(text) is True


@pytest.mark.parametrize("text", GENERIC_ONLY_POSITIVES)
def test_non_content_ingestion_prompts_match_generic_only(text: str) -> None:
    assert wants_external_entity_ingest(text) is True
    assert wants_external_content_ingest(text) is False


@pytest.mark.parametrize("text", NEGATIVES)
def test_outbound_or_unrelated_automation_does_not_match(text: str) -> None:
    assert wants_external_entity_ingest(text) is False
    assert wants_external_content_ingest(text) is False


def test_source_alone_or_action_alone_is_not_enough() -> None:
    # No target named at all.
    assert wants_external_entity_ingest("Connect to Airtable and send updates") is False
    # No source named at all.
    assert wants_external_entity_ingest("Push new articles into the site") is False
