<?php

declare(strict_types=1);

namespace Plugin\tnt_stabila_shop\src\Abstracts;

use Plugin\tnt_stabila_shop\src\Interfaces\PaginatedDataInterface;

class AbstractTableData
{
    /**
     * @param list<object> $rows
     */
    public function __construct(
        protected object $header,
        protected array $rows,
        protected string $tplName,
        protected PaginatedDataInterface $pagination
    ) {
        if (empty($rows[0]) === false && \count(\get_object_vars($header)) !== \count(\get_object_vars($rows[0]))) {
            throw new \InvalidArgumentException('Header and rows must have the same number of columns.');
        }
    }

    public function getHeader(): object
    {
        return $this->header;
    }

    /**
     * @return list<object>
     */
    public function getRows(): array
    {
        return $this->rows;
    }

    public function getTemplateName(): string
    {
        return $this->tplName;
    }

    public function getPagination(): PaginatedDataInterface
    {
        return $this->pagination;
    }
}
