/**
 * Test script for Config API
 * Run: node test-config-api.js
 */

const axios = require('axios');

const BASE_URL = 'http://localhost:3000/api/v1';

async function testPublicConfigAPI() {
  console.log('\n=== 测试公开配置API ===\n');
  
  try {
    const response = await axios.get(`${BASE_URL}/config`);
    console.log('✅ GET /api/v1/config');
    console.log('状态码:', response.status);
    console.log('响应数据:', JSON.stringify(response.data, null, 2));
  } catch (error) {
    console.error('❌ 请求失败:', error.response?.data || error.message);
  }
}

async function testAdminConfigAPI() {
  console.log('\n=== 测试管理后台配置API (需要登录) ===\n');
  
  // 首先需要登录获取token
  console.log('提示: 需要先登录管理后台获取token');
  console.log('登录接口: POST /api/v1/admin/auth/login');
  console.log('请求体: { "username": "admin", "password": "your_password" }');
  console.log('\n然后使用返回的token访问以下接口:');
  console.log('- GET /api/v1/admin/config (获取所有配置)');
  console.log('- GET /api/v1/admin/config/:key (获取单个配置)');
  console.log('- PUT /api/v1/admin/config/:key (更新配置)');
  console.log('- DELETE /api/v1/admin/config/:key (删除配置)');
}

async function main() {
  console.log('🚀 开始测试Config API...\n');
  console.log('确保后端服务正在运行: http://localhost:3000');
  
  await testPublicConfigAPI();
  await testAdminConfigAPI();
  
  console.log('\n✨ 测试完成!');
  console.log('\n📚 查看完整API文档: http://localhost:3000/api-docs');
}

main().catch(console.error);
