@echo off
REM Client Approval System - Production Deployment Script for Windows
REM Run this script to deploy the client approval system to production

echo ====================================================
echo   CLIENT APPROVAL SYSTEM - PRODUCTION DEPLOYMENT
echo ====================================================
echo.

REM Check if manage.py exists
if not exist "manage.py" (
    echo Error: manage.py not found. Please run this script from the project root.
    exit /b 1
)

echo [Step 1] Checking database connection...
python manage.py check --database default
if errorlevel 1 (
    echo Database connection check failed
    exit /b 1
)
echo Database connection successful
echo.

echo [Step 2] Creating database backup...
echo Note: This script does not create a backup automatically.
echo Please ensure you have a recent database backup before proceeding.
set /p continue="Continue without backup? (y/n): "
if /i not "%continue%"=="y" (
    echo Deployment cancelled by user.
    exit /b 1
)
echo Proceeding with deployment
echo.

echo [Step 3] Checking for pending migrations...
python manage.py showmigrations users
echo.

echo [Step 4] Applying migrations...
python manage.py migrate users
if errorlevel 1 (
    echo Migration failed
    exit /b 1
)
echo Migrations applied successfully
echo.

echo [Step 5] Verifying migration...
python manage.py check --database default
if errorlevel 1 (
    echo Verification failed
    exit /b 1
)
echo Verification successful
echo.

echo [Step 6] Collecting static files (if needed)...
python manage.py collectstatic --noinput
echo Static files collected
echo.

echo ====================================================
echo   CLIENT APPROVAL SYSTEM DEPLOYED SUCCESSFULLY
echo ====================================================
echo.
echo Next steps:
echo   1. Test the pending clients page: http://your-domain/users/clients/pending/
echo   2. Test approving a client
echo   3. Test rejecting a client
echo   4. Monitor the audit logs
echo.
echo For admins:
echo   - Navigate to the Clients page
echo   - Click the 'Pending Approvals' button
echo   - Approve or reject clients as needed
echo.

pause

