"""
demo.py
--------
Interactive command-line demo of the MindScreen AI core logic (chatbot +
screening + risk engine), with no web server / DB required.

Run:
    python3 -m mindscreen.demo
"""

import json
from .conversation_manager import ConversationManager


def main():
    print("=" * 70)
    print("MindScreen AI — CLI Demo (research/educational prototype)")
    print("=" * 70)
    cm = ConversationManager(participant_id="DEMO-001")
    bot_msg = cm.start()
    print(f"\nBOT: {bot_msg}\n")

    while True:
        try:
            user_text = input("YOU: ").strip()
        except (EOFError, KeyboardInterrupt):
            print("\n[session ended]")
            break
        if not user_text:
            continue

        out = cm.handle_user_turn(user_text)
        print(f"\nBOT: {out['bot_message']}\n")

        if out["stage"].value == "safety_paused":
            # Keep the loop alive in case the user wants to say more, but
            # automated screening does not resume after a safety pause.
            continue

        if out["stage"].value == "complete":
            if out["result"] is not None:
                print("-" * 70)
                print("SCREENING RESULT (research/educational use only — not a diagnosis)")
                print("-" * 70)
                print(json.dumps(out["result"].to_dict(), indent=2))
            break


if __name__ == "__main__":
    main()
