import axios from 'axios';

async function testCurrentLogs() {
  try {
    console.log('🔐 先登录获取token...');
    
    // 登录获取token
    const loginResponse = await axios.post('http://49.51.70.206:3000/api/auth/login', {
      username: 'admin',
      password: '123456'
    });
    
    const token = loginResponse.data.data.accessToken;
    console.log('✅ 登录成功，获取到token');
    
    console.log('🔍 测试当前日志API...');
    
    // 测试系统日志API
    const logsResponse = await axios.get('http://49.51.70.206:3000/api/system/logs', {
      headers: {
        'Authorization': `Bearer ${token}`
      },
      params: {
        page: 1,
        limit: 10
      }
    });
    
    console.log('📊 日志API响应状态:', logsResponse.status);
    console.log('📋 日志数据:', JSON.stringify(logsResponse.data, null, 2));
    console.log('📈 日志总数:', logsResponse.data.data?.pagination?.total || 0);
    console.log('📄 当前页日志数量:', logsResponse.data.data?.logs?.length || 0);
    
    // 测试仪表板统计API
    const statsResponse = await axios.get('http://49.51.70.206:3000/api/dashboard/stats', {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    console.log('\n📊 仪表板统计响应状态:', statsResponse.status);
    console.log('📋 统计数据:', JSON.stringify(statsResponse.data, null, 2));
    
    // 测试最近活动API
    const activitiesResponse = await axios.get('http://49.51.70.206:3000/api/dashboard/recent-activities', {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    console.log('\n📊 最近活动响应状态:', activitiesResponse.status);
    console.log('📋 活动数据:', JSON.stringify(activitiesResponse.data, null, 2));
    console.log('📈 活动总数:', activitiesResponse.data.data?.length || 0);
    
  } catch (error) {
    console.error('❌ 测试失败:', error.message);
    if (error.response) {
      console.error('错误状态:', error.response.status);
      console.error('错误数据:', error.response.data);
    }
  }
}

testCurrentLogs().catch(console.error);