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

from .models import PostizInstallBrief


class PostizPagesTests(TestCase):
    def test_home_page_loads(self):
        response = self.client.get(reverse("home"))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Plan a native Postiz development install")

    def test_create_brief_flow(self):
        response = self.client.post(
            reverse("brief_create"),
            {
                "title": "Primary VM",
                "public_url": "https://postiz.example.com",
                "node_version": "20 LTS",
                "package_manager": "pnpm",
                "postgres_ready": "on",
                "redis_ready": "on",
                "temporal_ready": "on",
                "email_provider": "smtp",
                "upload_strategy": "local",
                "notes": "Ready to bootstrap.",
            },
            follow=True,
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(PostizInstallBrief.objects.count(), 1)
        brief = PostizInstallBrief.objects.get()
        self.assertContains(response, brief.title)
        self.assertContains(response, "Ready for repo bootstrap")

    def test_brief_list_empty_state(self):
        response = self.client.get(reverse("brief_list"))
        self.assertContains(response, "No install briefs yet")
