@echo off
REM PWA Schema Setup - Run this batch file to set up PWA database tables
REM Make sure MySQL is running and update credentials as needed

setlocal enabledelayedexpansion

echo.
echo ================================
echo PWA Schema Setup for Inventory Counter
echo ================================
echo.

REM Check if MySQL is available
where mysql >nul 2>nul
if errorlevel 1 (
    echo ERROR: MySQL is not found in PATH
    echo Please ensure MySQL is installed and added to your system PATH
    pause
    exit /b 1
)

REM Ask for credentials
set /p user="Enter MySQL username [root]: " || set "user=root"
set /p password="Enter MySQL password [blank for none]: "
set /p database="Enter database name [invcount]: " || set "database=invcount"

echo.
echo Connecting to MySQL and running PWA schema...
echo.

REM Run the schema file
if "%password%"=="" (
    mysql -u %user% %database% < database/pwa-schema.sql
) else (
    mysql -u %user% -p%password% %database% < database/pwa-schema.sql
)

if errorlevel 1 (
    echo.
    echo ERROR: Schema setup failed
    pause
    exit /b 1
)

echo.
echo ================================
echo PWA Schema Setup Complete!
echo ================================
echo.
echo Next steps:
echo 1. Update config/config.php with VAPID keys
echo 2. Run 'web-push generate-vapid-keys' to generate VAPID keys
echo 3. Test offline functionality in DevTools
echo.
pause
