<?php

declare(strict_types=1);

namespace Autogedal\FeedMonitor\Model\Config;

use Autogedal\FeedMonitor\Model\JobRegistry;
use Magento\Config\Model\Config\CommentInterface;
use Magento\Framework\Escaper;

/**
 * Comment of the "max age" field: the syntax and the default interval of every monitored job.
 */
class MaxAgeComment implements CommentInterface
{
    public function __construct(
        private readonly JobRegistry $jobs,
        private readonly Escaper $escaper
    ) {
    }

    /**
     * @param string $elementValue
     */
    public function getCommentText($elementValue)
    {
        $defaults = array_map(
            fn (string $jobCode): string => $this->escaper->escapeHtml(
                $jobCode . '=' . ($this->jobs->getDefaultMaxAgeMinutes($jobCode) ?? 'fara program regulat')
            ),
            $this->jobs->getJobCodes()
        );

        return 'Daca un job (sau un sub-feed) nu porneste in acest interval, se trimite alerta. Cate unul pe linie: '
            . 'job=minute; joburile nelistate folosesc valoarea implicita.<br/>Implicit: ' . implode(', ', $defaults);
    }
}
