from autoshorts.demo.truetrace_concepts import (
    build_truetrace_concept_batch,
    render_truetrace_concept_summary,
)
from autoshorts.strategy.brand import TRUETRACE_SHORTS_BRAND, validate_candidate_brand_fit
from autoshorts.strategy.series import validate_candidate_series_fit


def test_truetrace_concept_batch_contains_five_public_safe_candidates():
    batch = build_truetrace_concept_batch()

    assert batch.batch_id == "truetrace-concept-testbatch-001"
    assert [candidate.candidate_id for candidate in batch.candidates] == [
        "truetrace-ai-automation-quiet-rot-38s",
        "truetrace-prompt-vs-system-workflow-breaks-35s",
        "truetrace-ai-notes-equal-importance-34s",
        "truetrace-ai-agents-tasks-not-teams-40s",
        "truetrace-review-before-automation-32s",
    ]
    assert all(candidate.platforms == ("youtube", "tiktok") for candidate in batch.candidates)
    assert all(candidate.pillar == "ai_life_systems" for candidate in batch.candidates)
    assert all("Brand: truetrace_shorts" in candidate.policy_notes for candidate in batch.candidates)


def test_truetrace_concepts_pass_brand_and_series_fit():
    expected_series = {
        "truetrace-ai-automation-quiet-rot-38s": "ai_system_autopsy",
        "truetrace-prompt-vs-system-workflow-breaks-35s": "prompt_vs_system",
        "truetrace-ai-notes-equal-importance-34s": "one_rule_one_example",
        "truetrace-ai-agents-tasks-not-teams-40s": "ai_hype_court",
        "truetrace-review-before-automation-32s": "one_rule_one_example",
    }

    for candidate in build_truetrace_concept_batch().candidates:
        brand_result = validate_candidate_brand_fit(candidate, TRUETRACE_SHORTS_BRAND)
        series_result = validate_candidate_series_fit(candidate, expected_series[candidate.candidate_id])

        assert brand_result.is_valid is True, brand_result.errors
        assert series_result.is_valid is True, series_result.errors
        public_text = " ".join(
            (
                candidate.title,
                candidate.hook,
                candidate.script_outline,
                candidate.visual_concept,
                candidate.caption,
                candidate.cta,
            )
        ).casefold()
        assert "jarvis" not in public_text
        assert "hermes" not in public_text
        assert "politic" not in public_text
        assert "collaboration" not in public_text


def test_render_truetrace_concept_summary_is_reviewable_without_action_language():
    text = render_truetrace_concept_summary()

    assert "## TrueTrace Concept Testbatch" in text
    assert "Candidates: 5" in text
    assert "Why Most AI Automations Break After Three Days" in text
    assert "This Prompt Looks Smart — But the Workflow Still Breaks" in text
    assert "The Hidden Reason Your AI Notes Become Useless" in text
    assert "Claim: AI Agents Will Replace Teams" in text
    assert "One Rule Before You Automate Anything With AI" in text
    assert "YouTube:" in text
    assert "TikTok:" in text
    assert "publish" not in text.casefold()
    assert "upload" not in text.casefold()
    assert "post" not in text.casefold()
