<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\Shell;

final class DesignerApplicationShellDefinition
{
    public function __construct(
        private readonly string $appId,
        private readonly string $title,
        private readonly array $navigation,
        private readonly array $dashboard,
        private readonly array $pages = [],
        private readonly array $authPages = [],
        private readonly array $routes = [],
        private readonly array $assets = [],
        private readonly array $meta = []
    ) {}

    public static function create(string $appId, string $title, array $navigation, array $dashboard, array $pages, array $authPages, array $routes, array $assets = []): self
    {
        return new self($appId, $title, $navigation, $dashboard, $pages, $authPages, $routes, $assets, ['version' => '1.0.0', 'createdAt' => date('c')]);
    }

    public function toArray(): array
    {
        return [
            'appId' => $this->appId,
            'id' => $this->appId,
            'type' => 'application_shell',
            'title' => $this->title,
            'navigation' => $this->navigation,
            'dashboard' => $this->dashboard,
            'pages' => $this->pages,
            'authPages' => $this->authPages,
            'routes' => $this->routes,
            'assets' => $this->assets,
            'meta' => $this->meta,
            'summary' => [
                'pages' => count($this->pages),
                'authPages' => count($this->authPages),
                'routes' => count($this->routes),
                'assets' => count((array) ($this->assets['manifest']['assets'] ?? [])),
            ],
        ];
    }
}
