"""
Unit tests for admin endpoints
"""

import pytest


class TestAdmin:
    """Test admin endpoints"""

    def test_get_system_stats(self, client, admin_token):
        """Test get system statistics"""
        response = client.get(
            '/api/v2/admin/stats',
            headers={'Authorization': f'Bearer {admin_token}'}
        )

        assert response.status_code == 200
        data = response.json()
        # API returns nested structure
        assert 'users' in data
        assert 'tasks' in data
        assert 'sessions' in data
        assert 'activity' in data
        assert 'total' in data['users']
        assert 'total' in data['tasks']

    def test_get_system_stats_non_admin(self, client, auth_token):
        """Test that non-admin cannot access admin endpoints"""
        response = client.get(
            '/api/v2/admin/stats',
            headers={'Authorization': f'Bearer {auth_token}'}
        )

        assert response.status_code == 403

    def test_list_users(self, client, admin_token):
        """Test list all users"""
        response = client.get(
            '/api/v2/admin/users',
            headers={'Authorization': f'Bearer {admin_token}'}
        )

        assert response.status_code == 200
        data = response.json()
        assert 'users' in data
        assert 'total' in data

    def test_get_audit_logs(self, client, admin_token):
        """Test get audit logs"""
        response = client.get(
            '/api/v2/admin/audit-logs',
            headers={'Authorization': f'Bearer {admin_token}'}
        )

        assert response.status_code == 200
        data = response.json()
        assert 'logs' in data
        assert 'total' in data
        assert 'page' in data
