#!/bin/bash
set -e

echo "========================================"
echo "  PMEPro - Script d'installation"
echo "========================================"

# Vérifications
if ! command -v php &> /dev/null; then
    echo "PHP n'est pas installé. Veuillez installer PHP >= 8.1"
    exit 1
fi

if [ ! -f "composer.json" ]; then
    echo "Erreur : composer.json non trouvé. Exécutez ce script depuis le répertoire du projet."
    exit 1
fi

echo "Installation des dépendances..."
composer install --no-dev --optimize-autoloader

echo "Configuration de l'environnement..."
cp .env.example .env
php artisan key:generate

echo "Configuration des variables d'environnement (vous pouvez modifier .env après)"
# L'utilisateur doit configurer .env manuellement

echo "Création des tables..."
php artisan migrate --force

echo "Ajout des données initiales..."
php artisan db:seed --force

echo "Optimisations..."
php artisan config:cache
php artisan route:cache
php artisan view:cache

echo "========================================"
echo "Installation terminée !"
echo "Accédez au site via : http://localhost"
echo "Identifiants test : admin@pmepro.demo / password"
echo "========================================"
