from __future__ import annotations

from django.test import TestCase
from django.urls import reverse

from core.models import Person, PersonIdentifier, User


class BehavioralGraphViewTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            username="behavior-user",
            email="behavior@example.com",
            password="pw",
        )
        self.client.force_login(self.user)
        self.person = Person.objects.create(user=self.user, name="Behavior Contact")
        PersonIdentifier.objects.create(
            user=self.user,
            person=self.person,
            service="signal",
            identifier="+15551234567",
        )

    def test_behavioral_graph_widget_renders_without_chartjs(self):
        response = self.client.get(
            reverse(
                "ai_workspace_insight_graphs",
                kwargs={"type": "widget", "person_id": self.person.id},
            )
        )

        self.assertEqual(200, response.status_code)
        content = response.content.decode("utf-8")
        self.assertIn("Behavioral Graphs", content)
        self.assertIn("MS", content)
        self.assertNotIn("chart.js", content.lower())

    def test_behavioral_information_page_uses_ms_ps_copy(self):
        response = self.client.get(
            reverse(
                "ai_workspace_information",
                kwargs={"type": "page", "person_id": self.person.id},
            )
        )

        self.assertEqual(200, response.status_code)
        self.assertContains(response, "MS / PS Information")
        self.assertContains(
            response, "Current message-state and presence-state signals"
        )

    def test_ai_person_widget_exposes_behavioral_launcher_only(self):
        response = self.client.get(
            reverse(
                "ai_workspace_person",
                kwargs={"type": "widget", "person_id": self.person.id},
            )
        )

        self.assertEqual(200, response.status_code)
        content = response.content.decode("utf-8")
        self.assertIn("Open MS / PS graphs, information, and help", content)
        self.assertIn(
            reverse(
                "ai_workspace_insight_graphs",
                kwargs={"type": "widget", "person_id": self.person.id},
            ),
            content,
        )
        self.assertNotIn("/insights/platform/", content)
        self.assertNotIn("/insights/stability_state/", content)
        self.assertNotIn("/insights/commitment_inbound/", content)
