"""Integration tests for admin settings endpoints."""

import pytest
from httpx import AsyncClient


class TestAdminSettings:

    @pytest.mark.asyncio
    async def test_list_settings(
        self, client: AsyncClient, admin_auth_headers: dict
    ):
        """List platform settings (may be empty if not seeded via migration)."""
        response = await client.get("/api/v1/admin/settings", headers=admin_auth_headers)
        assert response.status_code == 200
        data = response.json()
        assert "settings" in data
        assert isinstance(data["settings"], dict)

    @pytest.mark.asyncio
    async def test_update_settings(
        self, client: AsyncClient, admin_auth_headers: dict
    ):
        """Update maintenance_mode setting."""
        response = await client.put(
            "/api/v1/admin/settings",
            json={"settings": {"maintenance_mode": "true"}},
            headers=admin_auth_headers,
        )
        assert response.status_code == 200

        # Verify change
        get_resp = await client.get("/api/v1/admin/settings", headers=admin_auth_headers)
        settings = get_resp.json()["settings"]
        assert settings["maintenance_mode"] is True or settings["maintenance_mode"] == "true"

    @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/settings", headers=auth_headers)
        assert response.status_code == 403
