@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

echo ========================================
echo 枚举接口测试脚本
echo ========================================
echo.

:: 设置基础URL和Token
set BASE_URL=http://localhost:8080
set USERNAME=admin
set PASSWORD=admin123

:: 第一步：获取Token
echo [1/4] 获取Token...
curl -s -X POST "%BASE_URL%/login/test?username=%USERNAME%&password=%PASSWORD%" -H "Content-Type: application/json" > temp_token.json

:: 使用jq提取token（如果没有jq，使用简单方法）
for /f "tokens=2 delims=:" %%a in ('type temp_token.json ^| findstr "token"') do (
    set TOKEN_STR=%%a
)
:: 去除引号和空格
set TOKEN=%TOKEN_STR:"=%
set TOKEN=%TOKEN: =%

if "%TOKEN%"=="" (
    echo 获取Token失败！
    type temp_token.json
    del temp_token.json
    exit /b 1
)
echo Token获取成功！
echo.

:: 保存测试结果
set OUTPUT_DIR=doc\test-scripts\test-results
if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"

:: 第二步：测试关系类型接口
echo [2/4] 测试关系类型接口 /ccdi/enum/relationType ...
curl -s -X GET "%BASE_URL%/ccdi/enum/relationType" ^
  -H "Authorization: Bearer %TOKEN%" ^
  -H "Content-Type: application/json" > "%OUTPUT_DIR%\enum_relationType.json"

type "%OUTPUT_DIR%\enum_relationType.json"
echo.
echo 关系类型接口测试完成！
echo.

:: 第三步：测试证件类型接口
echo [3/4] 测试证件类型接口 /ccdi/enum/certType ...
curl -s -X GET "%BASE_URL%/ccdi/enum/certType" ^
  -H "Authorization: Bearer %TOKEN%" ^
  -H "Content-Type: application/json" > "%OUTPUT_DIR%\enum_certType.json"

type "%OUTPUT_DIR%\enum_certType.json"
echo.
echo 证件类型接口测试完成！
echo.

:: 清理临时文件
del temp_token.json

:: 第四步：生成测试报告
echo [4/4] 生成测试报告...
set REPORT_FILE=%OUTPUT_DIR%\enum-test-report.md

echo # 枚举接口测试报告 > %REPORT_FILE%
echo. >> %REPORT_FILE%
echo 测试时间: %date% %time% >> %REPORT_FILE%
echo. >> %REPORT_FILE%

echo ## 1. 关系类型接口测试结果 >> %REPORT_FILE%
echo. >> %REPORT_FILE%
echo **接口地址**: GET /ccdi/enum/relationType >> %REPORT_FILE%
echo. >> %REPORT_FILE%
echo **响应数据**: >> %REPORT_FILE%
echo ```json >> %REPORT_FILE%
type "%OUTPUT_DIR%\enum_relationType.json" >> %REPORT_FILE%
echo ``` >> %REPORT_FILE%
echo. >> %REPORT_FILE%

echo ## 2. 证件类型接口测试结果 >> %REPORT_FILE%
echo. >> %REPORT_FILE%
echo **接口地址**: GET /ccdi/enum/certType >> %REPORT_FILE%
echo. >> %REPORT_FILE%
echo **响应数据**: >> %REPORT_FILE%
echo ```json >> %REPORT_FILE%
type "%OUTPUT_DIR%\enum_certType.json" >> %REPORT_FILE%
echo ``` >> %REPORT_FILE%
echo. >> %REPORT_FILE%

echo ========================================
echo 测试完成！
echo 测试报告已保存到: %REPORT_FILE%
echo ========================================
