<?php

declare(strict_types=1);

namespace PpPhp\Core\Assets;

final class AssetRegistry
{
    /** @var array<string, AssetPackage> */
    private static array $packages = [];

    /** @var string[] */
    private static array $enabled = [];

    public static function register(AssetPackage $package): void
    {
        self::$packages[$package->id] = $package;
    }

    public static function enable(string $packageId): void
    {
        if (!in_array($packageId, self::$enabled, true)) {
            self::$enabled[] = $packageId;
        }
    }

    public static function has(string $packageId): bool
    {
        return isset(self::$packages[$packageId]);
    }

    public static function get(string $packageId): ?AssetPackage
    {
        return self::$packages[$packageId] ?? null;
    }

    /** @return array<string, AssetPackage> */
    public static function packages(): array
    {
        return self::$packages;
    }

    /** @return string[] */
    public static function enabled(): array
    {
        return self::$enabled;
    }

    public static function reset(): void
    {
        self::$packages = [];
        self::$enabled = [];
    }
}
