<?php

declare(strict_types=1);

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

use apexl\Io\modules\tabulator\Dto\RowFormatterDto\TabulatorRowFormatterDto;
use apexl\Io\modules\tabulator\Interfaces\TabulatorRowFormatterInterface;
use apexl\Utils\Class\ClassBasename;
use function apexl\Io\assertInstanceOf;

readonly abstract class RowFormatter implements TabulatorRowFormatterInterface
{
    public function __construct(protected array $parameters = [])
    {
        foreach ($this->parameters as $condition) {
            assertInstanceOf($condition, $this->dtoClass());
        }
    }

    /**
     * @return class-string<TabulatorRowFormatterDto>
     */
    abstract protected function dtoClass(): string;

    public function jsonSerialize(): array
    {
        return [
            'name' => ClassBasename::classBasename(static::class),
            'params' => $this->parameters,
        ];
    }
}