@echo off
setlocal
:: バッチファイルの場所をカレントディレクトリにする
pushd "%~dp0"
set "PROJECT_ROOT=%CD%"
set "UV_PROJECT_ENVIRONMENT=.venv-win"

echo ===================================================
echo   Rithmic Bridge Publisher for Windows
echo ===================================================

echo.
echo [1/3] Installing/Syncing dependencies with uv...
uv sync --all-extras
if %ERRORLEVEL% NEQ 0 (
    echo [ERROR] Dependency installation failed.
    pause
    exit /b %ERRORLEVEL%
)

echo.
echo [2/3] Checking environment configuration...
if not exist .env (
    echo [WARNING] .env file not found. Copying from .env.example...
    copy .env.example .env
    echo Please edit .env file with your Rithmic credentials and restart this script.
    pause
    exit /b 1
)

echo.
echo [3/3] Starting Publisher...
echo Press Ctrl+C to stop.
echo.

:: 実行パスを絶対パスで指定
set "PYTHON_EXE=%PROJECT_ROOT%\.venv-win\Scripts\python.exe"

:: 実行
"%PYTHON_EXE%" tools\launcher.py %*

if %ERRORLEVEL% NEQ 0 (
    echo [ERROR] Publisher exited with error code %ERRORLEVEL%.
    pause
)

popd
