<?php

declare(strict_types=1);

namespace App\Scolarite\Domain\Policy;

use App\Scolarite\Domain\Model\Evaluation\Evaluation;
use App\Shared\Domain\Clock;

final readonly class VisibiliteNotesPolicy
{
    private const int DELAI_PARENTS_HEURES = 24;

    public function __construct(
        private Clock $clock,
    ) {
    }

    public function visiblePourEleve(Evaluation $evaluation): bool
    {
        return $evaluation->notesPubliees();
    }

    public function visiblePourParent(Evaluation $evaluation): bool
    {
        if (!$evaluation->notesPubliees()) {
            return false;
        }

        $delai = $evaluation->gradesPublishedAt?->modify('+' . self::DELAI_PARENTS_HEURES . ' hours');

        return $delai !== null && $delai <= $this->clock->now();
    }
}
