<?php

declare(strict_types=1);

namespace App\Application\Admin;

use App\Application\Admin\ValueObjects\RouteCollection;
use App\Framework\View\Template;

#[Template('routes')]
final readonly class RoutesViewModel
{
    public string $name;

    public string $title;

    public function __construct(
        public RouteCollection $routes,
        string $name = 'Michael',
        string $title = 'Routes'
    ) {
        $this->name = $name;
        $this->title = $title;
    }

    /**
     * @param list<array<string, mixed>> $routes
     */
    public static function fromArray(array $routes, string $name = 'Michael', string $title = 'Routes'): self
    {
        return new self(
            RouteCollection::fromArray($routes),
            $name,
            $title
        );
    }

    /**
     * Get the routes as an iterable for the template engine
     * @return \Traversable<int, array<string, mixed>>
     */
    public function getRoutes(): \Traversable
    {
        return $this->routes->getIterator();
    }
}
