import pytest

from autoshorts.demo.sample_batch import render_sample_review_batch
from autoshorts.telegram.review_sender import prepare_review_delivery


def test_prepare_review_delivery_wraps_review_text_without_side_effects():
    text = render_sample_review_batch()

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

    assert delivery.topic == "review"
    assert delivery.text == text
    assert delivery.delivery_type == "telegram_review"
    assert delivery.requires_human_approval is True
    assert delivery.side_effects == ()
    assert "## Review Batch: sample-ai-life-systems" in delivery.text


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


def test_prepare_review_delivery_rejects_publishing_language():
    with pytest.raises(ValueError, match="unsafe publishing language"):
        prepare_review_delivery("Ready to publish this candidate")

    with pytest.raises(ValueError, match="unsafe publishing language"):
        prepare_review_delivery("Ready to post this candidate")


def test_prepare_review_delivery_rejects_overlong_telegram_text():
    with pytest.raises(ValueError, match="Telegram message exceeds"):
        prepare_review_delivery("x" * 4097)
