<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Manifest;

final class ManifestFactory
{
    public static function fromArray(array $data, string $source = ''): ManifestRecord
    {
        return new ManifestRecord(
            id: (string)($data['id'] ?? ''),
            type: (string)($data['type'] ?? 'package'),
            label: (string)($data['label'] ?? $data['name'] ?? $data['id'] ?? 'Unknown'),
            version: (string)($data['version'] ?? '1.0.0'),
            status: (string)($data['status'] ?? 'active'),
            description: (string)($data['description'] ?? ''),
            services: is_array($data['services'] ?? null) ? $data['services'] : [],
            dependencies: is_array($data['dependencies'] ?? null) ? $data['dependencies'] : [],
            capabilities: is_array($data['capabilities'] ?? null) ? $data['capabilities'] : [],
            raw: $data,
            source: $source
        );
    }
}
