from django.views.generic import TemplateView
from accounts.mixins import ScannerAccessMixin
from core.models import ScanLog
from django.utils import timezone

class WelcomeAgentView(ScannerAccessMixin, TemplateView):
    """Page d'accueil de l'agent. Affiche ses statistiques de la journée."""
    template_name = 'scanner/welcome.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        # On calcule combien de tickets cet agent a scanné avec succès aujourd'hui
        aujourd_hui = timezone.now().date()
        scans_jour = ScanLog.objects.filter(
            agent_scan=self.request.user,
            resultat=ScanLog.Resultat.SUCCES,
            date_scan__date=aujourd_hui
        ).count()
        context['scans_jour'] = scans_jour
        return context

class ScannerActiveView(ScannerAccessMixin, TemplateView):
    """Page contenant l'interface caméra (html5-qrcode)."""
    template_name = 'scanner/scanner_active.html'