<?php

declare(strict_types=1);

namespace apexl\Io\modules\tabulator\Tabulatable\ColumnCallback;

use apexl\Io\modules\tabulator\Interfaces\HasTabulatorViewInterface;
use apexl\Io\modules\tabulator\Interfaces\TabulatableColumnCallback;
use DateTimeInterface;

final readonly class Date implements TabulatableColumnCallback
{
    public function __invoke(HasTabulatorViewInterface $entity, string $field): string
    {
        $value = $entity->{$field};

        return $value instanceof DateTimeInterface
            ? $value->format('Y-m-d H:i:s')
            : 'None';
    }
}
