<?php

declare(strict_types=1);

namespace App\Administration\Application\Query\HasStudentsInClass;

use App\Administration\Domain\Model\SchoolClass\ClassId;
use App\Administration\Domain\Repository\ClassAssignmentRepository;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler(bus: 'query.bus')]
final readonly class HasStudentsInClassHandler
{
    public function __construct(
        private ClassAssignmentRepository $classAssignmentRepository,
    ) {
    }

    public function __invoke(HasStudentsInClassQuery $query): int
    {
        return $this->classAssignmentRepository->countByClass(
            ClassId::fromString($query->classId),
        );
    }
}
