@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
REM ========= CONFIGURA AQUI =========
set HOST=localhost
set DB=thirty
set USER=Fresh
set PASS=9j\V<2&2-f02Pre5(R=~E<$wg}.N:B
REM Si PHP no está en PATH, ajusta esta ruta (XAMPP por ejemplo):
set PHP_EXE=php
REM set PHP_EXE=C:\xampp\php\php.exe
REM ==================================

set BASE=%~dp0
set CSV_MUN=%BASE%municipalities_full.csv
set CSV_CP=%BASE%postal_codes_full.csv
set IMPORT_PHP=%BASE%import_locations.php

echo.
echo == 1) Dependencias Python: requests ==
pip install requests || python -m pip install requests || (echo [ERROR] No se pudo instalar 'requests' && exit /b 1)

echo.
echo == 2) Generando municipalities_full.csv ==
python "%BASE%build_municipalities_csv.py" || (echo [ERROR] Fallo generando municipalities_full.csv && exit /b 1)

echo.
echo == 3) Generando postal_codes_full.csv ==
python "%BASE%build_postal_codes_csv.py" || (echo [ERROR] Fallo generando postal_codes_full.csv && exit /b 1)

echo.
echo == 4) Importando en MySQL (provincias + municipios + C.P.) ==
"%PHP_EXE%" "%IMPORT_PHP%" --host=%HOST% --db=%DB% --user=%USER% --pass="%PASS%" --seed-provinces --municipalities="%CSV_MUN%" --postalcodes="%CSV_CP%"
if errorlevel 1 (echo [ERROR] Fallo en import_locations.php && exit /b 1)

echo.
echo ==== TODO LISTO ====
exit /b 0
