from django.views.generic import TemplateView
from .models import HeroSection, ValueProposition, Statistic, CallToAction

# Imports Cross-Apps (Le coeur de l'agrégation)
from projects.models import Project
from services.models import Service

class HomeView(TemplateView):
    template_name = 'home/index.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        
        # 1. Données propres à Home
        context['hero'] = HeroSection.objects.first()
        context['values'] = ValueProposition.objects.all()
        context['stats'] = Statistic.objects.all()
        context['cta'] = CallToAction.objects.first()
        
        # 2. Projets à la Une (Featured)
        # On en prend 3 ou 4 maximum pour ne pas surcharger
        context['featured_projects'] = Project.objects.filter(is_featured=True).order_by('order', '-date')[:3]
        
        # 3. Services (Aperçu)
        # On affiche les 4 premiers services
        context['featured_services'] = Service.objects.all().order_by('order')[:4]
        
        return context