"""Integration tests for admin plan limits and account override endpoints."""

import pytest
from httpx import AsyncClient


class TestAdminPlanLimits:

    @pytest.mark.asyncio
    async def test_list_plan_limits(
        self, client: AsyncClient, admin_auth_headers: dict
    ):
        """List all plan limits."""
        response = await client.get("/api/v1/admin/plan-limits", headers=admin_auth_headers)
        assert response.status_code == 200
        plans = response.json()
        assert len(plans) >= 3  # free, pro, team seeded in conftest
        plan_names = [p["plan"] for p in plans]
        assert "free" in plan_names

    @pytest.mark.asyncio
    async def test_update_plan_limits(
        self, client: AsyncClient, admin_auth_headers: dict
    ):
        """Update a plan's limits."""
        response = await client.put(
            "/api/v1/admin/plan-limits",
            json={
                "plan": "free",
                "max_trees": 5,
                "max_sessions_per_month": 30,
                "max_users": 2,
                "custom_branding": False,
                "priority_support": False,
                "export_formats": ["markdown", "text"],
            },
            headers=admin_auth_headers,
        )
        assert response.status_code == 200
        data = response.json()
        assert data["max_trees"] == 5

    @pytest.mark.asyncio
    async def test_list_account_overrides(
        self, client: AsyncClient, admin_auth_headers: dict
    ):
        """List account overrides."""
        response = await client.get("/api/v1/admin/account-overrides", headers=admin_auth_headers)
        assert response.status_code == 200
        assert isinstance(response.json(), list)

    @pytest.mark.asyncio
    async def test_non_admin_cannot_access(
        self, client: AsyncClient, auth_headers: dict
    ):
        """Non-admin gets 403."""
        response = await client.get("/api/v1/admin/plan-limits", headers=auth_headers)
        assert response.status_code == 403
