@echo off
title Pharmacy Sync Server - Windows Auto-Start Installer
cd /d "%~dp0"

set "SERVER_BAT=%~dp0Pharmacy_Local_Server.bat"
set "STARTUP_VBS=%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\PharmacySyncServerSilent.vbs"

if not exist "%SERVER_BAT%" (
    echo ==============================================================
    echo   [!] Please place this file in the same folder next to:
    echo       Pharmacy_Local_Server.bat
    echo ==============================================================
    pause
    exit /b 1
)

if exist "%STARTUP_VBS%" (
    del /f /q "%STARTUP_VBS%"
    echo ==============================================================
    echo   [REMOVED] Auto-start with Windows has been disabled.
    echo   Run this file again anytime to re-enable it.
    echo ==============================================================
    pause
    exit /b 0
)

> "%STARTUP_VBS%" (
    echo Set WshShell = CreateObject^("WScript.Shell"^)
    echo WshShell.CurrentDirectory = "%~dp0"
    echo WshShell.Run """%SERVER_BAT%"" --silent", 0, False
)

wscript.exe "%STARTUP_VBS%"

echo ==============================================================
echo   [SUCCESS] Silent Auto-Start Enabled and Server Started Now!
echo   The Sync Server will now run automatically in the background
echo   every time Windows starts (with NO console window).
echo   Run this file again anytime if you wish to disable Auto-Start.
echo ==============================================================
pause
