import pytest

from autoshorts.social.delivery import SocialDraftDelivery, prepare_social_draft_delivery


def test_prepare_social_draft_delivery_wraps_review_text_without_side_effects():
    text = "## Social Media Draft Review\nCandidate: example\nFreigabe alle"

    delivery = prepare_social_draft_delivery(text, topic="review")

    assert isinstance(delivery, SocialDraftDelivery)
    assert delivery.delivery_type == "social_draft_review"
    assert delivery.topic == "review"
    assert delivery.text == text
    assert delivery.requires_human_approval is True
    assert delivery.side_effects == ()


def test_prepare_social_draft_delivery_rejects_blank_text():
    with pytest.raises(ValueError, match="review text is required"):
        prepare_social_draft_delivery("   ")


def test_prepare_social_draft_delivery_rejects_long_text():
    with pytest.raises(ValueError, match="Telegram message exceeds 4096 characters"):
        prepare_social_draft_delivery("x" * 4097)


def test_prepare_social_draft_delivery_rejects_action_language():
    with pytest.raises(ValueError, match="social draft delivery must not imply publishing"):
        prepare_social_draft_delivery("please publish this")

    with pytest.raises(ValueError, match="social draft delivery must not imply publishing"):
        prepare_social_draft_delivery("please post this")
