@echo off
echo ============================================
echo  AutoIngest - Build and Publish
echo ============================================
echo.

REM Check for .NET 8 SDK
where dotnet >nul 2>&1
if %errorlevel% neq 0 (
    echo ERROR: .NET 8 SDK not found.
    echo Install it from: https://dotnet.microsoft.com/download/dotnet/8.0
    pause
    exit /b 1
)

echo Restoring NuGet packages...
cd /d "%~dp0AutoIngest"
dotnet restore
if %errorlevel% neq 0 (
    echo ERROR: NuGet restore failed.
    pause
    exit /b 1
)

echo.
echo Building Release...
dotnet publish -c Release -r win-x64 --self-contained false -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -o ..\publish
if %errorlevel% neq 0 (
    echo ERROR: Build failed.
    pause
    exit /b 1
)

echo.
echo ============================================
echo  BUILD SUCCESS
echo  Output: publish\AutoIngest.exe
echo ============================================
echo.
echo NOTE: This requires .NET 8 Desktop Runtime on the target PC.
echo Windows 11 already has it. For Windows 10, get it from:
echo   https://dotnet.microsoft.com/download/dotnet/8.0
echo.
pause
