<?php

declare(strict_types=1);

namespace PpPhp\Core\Platform\Services\Metadata;

final class ServiceMetadata
{
    /**
     * @param ServiceDependency[] $dependencies
     * @param CapabilityMetadata[] $capabilities
     * @param ServiceAlias[] $aliases
     * @param ServiceTag[] $tags
     */
    public function __construct(
        private readonly string $id,
        private readonly string $label,
        private readonly string $version = '1.0.0',
        private readonly string $description = '',
        private readonly array $dependencies = [],
        private readonly array $capabilities = [],
        private readonly array $aliases = [],
        private readonly array $tags = [],
        private readonly string $lifecycle = 'singleton',
        private readonly string $visibility = 'public',
        private readonly bool $lazy = true,
        private readonly array $metadata = []
    ) {
    }

    public function id(): string { return $this->id; }

    public function label(): string { return $this->label; }

    public function version(): string { return $this->version; }

    public function description(): string { return $this->description; }

    public function dependencies(): array { return $this->dependencies; }

    public function capabilities(): array { return $this->capabilities; }

    public function aliases(): array { return $this->aliases; }

    public function tags(): array { return $this->tags; }

    public function lifecycle(): string { return $this->lifecycle; }

    public function visibility(): string { return $this->visibility; }

    public function lazy(): bool { return $this->lazy; }

    public function metadata(): array { return $this->metadata; }

    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'label' => $this->label,
            'version' => $this->version,
            'description' => $this->description,
            'dependencies' => array_map(static fn (ServiceDependency $d): array => $d->toArray(), $this->dependencies),
            'capabilities' => array_map(static fn (CapabilityMetadata $c): array => $c->toArray(), $this->capabilities),
            'aliases' => array_map(static fn (ServiceAlias $a): array => $a->toArray(), $this->aliases),
            'tags' => array_map(static fn (ServiceTag $t): array => $t->toArray(), $this->tags),
            'lifecycle' => $this->lifecycle,
            'visibility' => $this->visibility,
            'lazy' => $this->lazy,
            'metadata' => $this->metadata,
        ];
    }
}
