<?php declare(strict_types=1);

namespace App\Twig;

use App\Service\SizeFormatter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class FilesizeExtension extends AbstractExtension
{
    public function __construct(
        private readonly SizeFormatter $sizeFormatter
    ) {
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('formatFilesize', [$this, 'formatFilesize']),
        ];
    }

    public function formatFilesize($size): string
    {
        return $this->sizeFormatter->formatSize($size);
    }
}
