@echo off
SET MYSQL_PATH="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe"

echo ========================================
echo MySQL Database Setup for Branch System
echo ========================================
echo.

REM Try to connect to MySQL and create database/user
echo Attempting to create database and user...
echo.

%MYSQL_PATH% -u root -e "CREATE DATABASE IF NOT EXISTS acbptxvs_branch_system CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER IF NOT EXISTS 'acbptxvs_phin'@'localhost' IDENTIFIED BY '5;)8.H8aTG8%%p_]'; GRANT ALL PRIVILEGES ON acbptxvs_branch_system.* TO 'acbptxvs_phin'@'localhost'; FLUSH PRIVILEGES;"

if %ERRORLEVEL% EQU 0 (
    echo.
    echo ========================================
    echo SUCCESS! Database setup complete.
    echo ========================================
    echo.
    echo You can now run: python manage.py runserver
    echo.
) else (
    echo.
    echo ========================================
    echo FAILED - Root password required
    echo ========================================
    echo.
    echo Please enter your MySQL root password when prompted:
    echo.
    %MYSQL_PATH% -u root -p -e "CREATE DATABASE IF NOT EXISTS acbptxvs_branch_system CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER IF NOT EXISTS 'acbptxvs_phin'@'localhost' IDENTIFIED BY '5;)8.H8aTG8%%p_]'; GRANT ALL PRIVILEGES ON acbptxvs_branch_system.* TO 'acbptxvs_phin'@'localhost'; FLUSH PRIVILEGES;"
    
    if %ERRORLEVEL% EQU 0 (
        echo.
        echo ========================================
        echo SUCCESS! Database setup complete.
        echo ========================================
        echo.
        echo You can now run: python manage.py runserver
        echo.
    ) else (
        echo.
        echo ========================================
        echo STILL FAILED
        echo ========================================
        echo.
        echo Please check:
        echo 1. MySQL is running
        echo 2. You have the correct root password
        echo 3. See reset_mysql_password.md for help
        echo.
    )
)

pause
