import os
import django
from pathlib import Path
from django.core.files import File

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aacore.settings')
django.setup()

from services.models import Service

print("=" * 60)
print("CRÉATION DU 5ÈME SERVICE")
print("=" * 60)
print()

# Vérifier s'il existe déjà
existing = Service.objects.filter(title__exact="30 Ans d'existence").first()
if existing:
    print(f"⚠️  Service '{existing.title}' existe déjà")
    print(f"   Mise à jour de l'image...")
    service = existing
else:
    print("Création du nouveau service 'Ans d'existence'...")
    service = Service.objects.create(
        title="30 Ans d'existence",
        short_description="Vous pouvez compter sur notre expérience et savoir-faire !",
        description="""
        Avec plus de 30 ans d'expérience dans le transport exceptionnel, 
        Transco 86 a développé un savoir-faire reconnu dans le domaine du TP et du Bâtiment.
        
        Notre longue expérience nous permet de :
        - Anticiper les problématiques de transport
        - Proposer des solutions adaptées à chaque situation
        - Garantir la sécurité de vos marchandises
        - Respecter les délais les plus exigeants
        
        Faites confiance à notre expertise !
        """,
        order=3,
        is_active=True
    )
    print(f"✅ Service créé : {service.title}")

# Ajouter l'image icon3.png
image_path = Path("media/services/icon3.png")
if image_path.exists():
    with open(image_path, 'rb') as f:
        service.image.save(image_path.name, File(f), save=True)
    print(f"✅ Image ajoutée : {service.image.url}")
else:
    print(f"❌ Fichier non trouvé : {image_path}")

print()
print("=" * 60)
print("TOUS LES SERVICES :")
print("=" * 60)
for s in Service.objects.all().order_by('order'):
    print(f"{s.order}. {s.title}")
    print(f"   Image : {s.image.url if s.image else 'Aucune'}")
print()
