<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\DataGrid;

final class DesignerDataGridPagination
{
    public function __construct(
        private readonly int $pageSize = 25,
        private readonly array $pageSizes = [10, 25, 50, 100],
        private readonly bool $showTotals = true,
        private readonly bool $showJumper = false
    ) {}

    public static function defaults(): self
    {
        return new self();
    }

    public static function fromArray(array $data): self
    {
        return new self(
            (int) ($data['pageSize'] ?? 25),
            (array) ($data['pageSizes'] ?? [10, 25, 50, 100]),
            (bool) ($data['showTotals'] ?? true),
            (bool) ($data['showJumper'] ?? false)
        );
    }

    public function toArray(): array
    {
        return [
            'pageSize' => $this->pageSize,
            'pageSizes' => $this->pageSizes,
            'showTotals' => $this->showTotals,
            'showJumper' => $this->showJumper,
        ];
    }
}
