<?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;

final readonly class Truthy implements TabulatableColumnCallback
{
    public function __construct(private ?string $field = null) {}

    public function __invoke(HasTabulatorViewInterface $entity, string $field): bool
    {
        return !!$entity->{$this->field ?? $field};
    }
}
