<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Service;

use App\Administration\Application\Port\TeacherAssignmentChecker;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\ClassId;
use App\Administration\Domain\Model\Subject\SubjectId;
use App\Administration\Domain\Model\User\UserId;
use App\Administration\Domain\Repository\TeacherAssignmentRepository;
use App\Shared\Domain\Tenant\TenantId;
use Override;

final readonly class RepositoryTeacherAssignmentChecker implements TeacherAssignmentChecker
{
    public function __construct(
        private TeacherAssignmentRepository $assignmentRepository,
    ) {
    }

    #[Override]
    public function estAffecte(
        UserId $teacherId,
        ClassId $classId,
        SubjectId $subjectId,
        AcademicYearId $academicYearId,
        TenantId $tenantId,
    ): bool {
        $assignment = $this->assignmentRepository->findByTeacherClassSubject(
            $teacherId,
            $classId,
            $subjectId,
            $academicYearId,
            $tenantId,
        );

        return $assignment !== null;
    }
}
