<?php

declare(strict_types=1);

namespace PpPhp\Core\Designer\Presets;

class DesignerPresetRegistry
{
    /**
     * @return array<class-string<DesignerPresetInterface>>
     */
    public static function all(): array
    {
        return [
            ExecutiveDashboardPreset::class,
            SalesDashboardPreset::class,
        ];
    }

    /**
     * @return array<class-string<DesignerPresetInterface>>
     */
    public static function byType(string $type): array
    {
        return array_values(array_filter(
            self::all(),
            fn(string $preset): bool => $preset::type() === $type
        ));
    }

    public static function find(string $type, string $id): ?string
    {
        foreach (self::byType($type) as $preset) {
            if ($preset::id() === $id) {
                return $preset;
            }
        }

        return null;
    }

    public static function metadata(string $type): array
    {
        return array_map(
            fn(string $preset): array => [
                'id' => $preset::id(),
                'name' => $preset::name(),
                'description' => $preset::description(),
                'icon' => $preset::icon(),
                'category' => $preset::category(),
                'type' => $preset::type(),
            ],
            self::byType($type)
        );
    }
}
