<?php

declare(strict_types=1);

namespace PpPhp\Core\Designer\Bridge;

use PpPhp\Core\Platform\Metadata\ValueObjects\PlatformMetadata;

/**
 * Bridge helper between legacy Designer component arrays and Platform metadata.
 *
 * This keeps DesignerComponent array-based for now while allowing new Platform
 * metadata to be stored in the existing component `meta` array.
 */
final class DesignerComponentBridge
{
    private function __construct() {}

    public static function attachMetadata(array $component, PlatformMetadata $metadata): array
    {
        $component['meta'] = $component['meta'] ?? [];
        $component['meta']['platform'] = $component['meta']['platform'] ?? [];
        $component['meta']['platform']['metadata'] = $metadata->toArray();

        return $component;
    }

    public static function platformMetadataArray(array $component): array
    {
        return $component['meta']['platform']['metadata'] ?? [];
    }

    public static function hasPlatformMetadata(array $component): bool
    {
        return !empty($component['meta']['platform']['metadata']) && is_array($component['meta']['platform']['metadata']);
    }
}
