<?php

declare(strict_types=1);

namespace App\Scolarite\Infrastructure\EventHandler;

use App\Scolarite\Application\Service\RecalculerMoyennesService;
use App\Scolarite\Domain\Event\EvaluationModifiee;
use App\Shared\Infrastructure\Tenant\TenantContext;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler(bus: 'event.bus')]
final readonly class RecalculerMoyennesOnEvaluationModifieeHandler
{
    public function __construct(
        private TenantContext $tenantContext,
        private RecalculerMoyennesService $service,
    ) {
    }

    public function __invoke(EvaluationModifiee $event): void
    {
        $tenantId = $this->tenantContext->getCurrentTenantId();

        $this->service->recalculerStatistiquesEvaluation($event->evaluationId, $tenantId);
        $this->service->recalculerTousElevesPourEvaluation($event->evaluationId, $tenantId);
    }
}
