<?php

declare(strict_types=1);

namespace App\Scolarite\Infrastructure\Persistence\InMemory;

use App\Scolarite\Domain\Model\Evaluation\ClassStatistics;
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
use App\Scolarite\Domain\Repository\EvaluationStatisticsRepository;
use Override;

final class InMemoryEvaluationStatisticsRepository implements EvaluationStatisticsRepository
{
    /** @var array<string, ClassStatistics> */
    private array $byEvaluationId = [];

    #[Override]
    public function save(EvaluationId $evaluationId, ClassStatistics $statistics): void
    {
        $this->byEvaluationId[(string) $evaluationId] = $statistics;
    }

    #[Override]
    public function findByEvaluation(EvaluationId $evaluationId): ?ClassStatistics
    {
        return $this->byEvaluationId[(string) $evaluationId] ?? null;
    }

    #[Override]
    public function delete(EvaluationId $evaluationId): void
    {
        unset($this->byEvaluationId[(string) $evaluationId]);
    }
}
