<?php

declare(strict_types=1);

namespace App\Framework\Admin\ValueObjects;

/**
 * Admin Table Configuration
 *
 * Configuration for creating admin data tables
 */
final readonly class AdminTableConfig
{
    /**
     * @param array<string, array{label: string, sortable?: bool, searchable?: bool, formatter?: string, class?: string}> $columns
     */
    public function __construct(
        public array $columns,
        public string $resource,
        public bool $sortable = true,
        public bool $searchable = true,
        public bool $paginated = true,
        public int $perPage = 25,
        public ?string $apiEndpoint = null,
    ) {
    }

    public static function create(
        string $resource,
        array $columns,
        bool $sortable = true,
        bool $searchable = true
    ): self {
        return new self(
            columns: $columns,
            resource: $resource,
            sortable: $sortable,
            searchable: $searchable,
            apiEndpoint: "/admin/api/{$resource}"
        );
    }

    public function getApiEndpoint(): string
    {
        return $this->apiEndpoint ?? "/admin/api/{$this->resource}";
    }
}
