@echo off
REM Run AI Brain regression tests

echo =====================================
echo AI Brain Regression Tests
echo =====================================
echo.

REM Check environment
echo Checking environment
uv --version >nul 2>&1
if %errorlevel% neq 0 (
    echo ERROR: uv not found. Please install uv package manager
    exit /b 1
)

uv run python -c "import pytest" >nul 2>&1
if %errorlevel% neq 0 (
    echo ERROR: pytest not found. Running uv sync to install dependencies
    uv sync
    if %errorlevel% neq 0 (
        echo ERROR: Failed to install dependencies with uv sync
        exit /b 1
    )
)

if not exist "C:\STM32F407\examples\實例1 跑馬燈實例" (
    echo ERROR: STM32 project template not found
    exit /b 1
)

if not exist "C:\Keil_v5\UV4\uv4.exe" (
    echo ERROR: Keil compiler not found
    exit /b 1
)

echo Environment OK
echo.

REM Parse arguments
set TEST_TYPE=%1
if "%TEST_TYPE%"=="" set TEST_TYPE=small

if "%TEST_TYPE%"=="small" (
    echo Running SMALL regression tests ^(3 error types x 2 runs = 6 tests^)
    echo This will take approximately 3-5 minutes
    echo.

    uv run pytest tests\integration\test_ai_regression.py::test_ai_fixes_error_small -s -v -m slow --tb=short --maxfail=5

) else if "%TEST_TYPE%"=="full" (
    echo Running FULL regression tests ^(10 error types x 10 runs = 100 tests^)
    echo WARNING: This will take approximately 50-60 minutes
    echo Press Ctrl+C to cancel
    timeout /t 5
    echo.

    uv run pytest tests\integration\test_ai_regression.py::test_ai_fixes_error_full -s -v -m slow --tb=short --maxfail=10

) else if "%TEST_TYPE%"=="report" (
    echo Generating success rate report
    echo.

    uv run pytest tests\integration\test_ai_regression.py::test_overall_success_rate -v --tb=short

) else (
    echo Usage: run_regression_tests.bat [small^|full^|report]
    echo   small  - Run small test suite (default, ~3-5 minutes)
    echo   full   - Run full test suite (~50-60 minutes)
    echo   report - Generate success rate report from existing results
    exit /b 1
)

echo.
echo =====================================
echo Test completed. Check regression_test_output.log for details.
echo =====================================