import argparse
from unittest.mock import MagicMock, patch

from GramAddict.core.resonance_engine import ResonanceEngine


def test_config_persona_mapping():
    """Verify that bot_flow.py correctly extracts persona from config arguments."""

    mock_args = argparse.Namespace()
    mock_args.ai_target_audience = "travel, photography, coffee"

    configs = MagicMock()
    configs.args = mock_args
    configs.username = "test_bot"

    # Simulating bot_flow.py lines 61-62
    persona_raw = getattr(configs.args, "ai_target_audience", getattr(configs.args, "persona_interests", ""))
    persona_interests = [p.strip() for p in persona_raw.split(",") if p.strip()] if persona_raw else []

    assert "coffee" in persona_interests
    assert len(persona_interests) == 3

    # Ensure ResonanceEngine accepts it without type tracebacks
    with (
        patch("GramAddict.core.resonance_engine.ContentMemoryDB"),
        patch("GramAddict.core.resonance_engine.ParasocialCRMDB"),
        patch("GramAddict.core.resonance_engine.PersonaMemoryDB"),
    ):
        engine = ResonanceEngine(configs.username, persona_interests=persona_interests)
        assert engine._persona_interests == ["travel", "photography", "coffee"]
