@echo off
:: import_migration_data.bat
:: Script to import database tables and product images from the template data on Windows.

echo Starting Migration Data Import...

set TEMPLATE_DIR=database\seeders\template_data
set SQL_FILE=%TEMPLATE_DIR%\migration_data.sql
set IMAGES_DIR=%TEMPLATE_DIR%\images

if not exist "%TEMPLATE_DIR%" (
    echo Error: Template data directory not found at %TEMPLATE_DIR%
    pause
    exit /b 1
)

echo 1/2: Importing database tables into gembira-db container...
if exist "%SQL_FILE%" (
    docker exec -i gembira-db mysql -ugembira_user -pchangeme gembira_ims < "%SQL_FILE%"
    if %errorlevel% equ 0 (
        echo Database tables imported successfully.
    ) else (
        echo Error importing database tables.
    )
) else (
    echo Warning: SQL file not found at %SQL_FILE%
)

echo 2/2: Restoring product images to gembira-backend container...
if exist "%IMAGES_DIR%" (
    docker exec gembira-backend mkdir -p /app/storage/app/public/products
    docker cp "%IMAGES_DIR%\." gembira-backend:/app/storage/app/public/products/
    
    if not exist "storage\app\public\products" mkdir "storage\app\public\products"
    xcopy /Y /E "%IMAGES_DIR%\*" "storage\app\public\products\" >nul 2>&1
    
    echo Product images restored successfully.
) else (
    echo Warning: Images template directory not found at %IMAGES_DIR%
)

echo Import Completed!
pause
