<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\DI\Definition;

use PpPhp\Core\Platform\DI\Contracts\ContainerInterface;
use PpPhp\Core\Platform\DI\Contracts\ResolverInterface;
use PpPhp\Core\Platform\DI\Metadata\DefinitionType;
use PpPhp\Core\Platform\DI\Metadata\Lifetime;

final class AliasDefinition extends AbstractDefinition
{
    public function __construct(string $id, private readonly string $target)
    {
        parent::__construct($id, Lifetime::ALIAS);
    }

    public function type(): string { return DefinitionType::ALIAS_SERVICE; }
    public function target(): string { return $this->target; }

    public function resolve(ContainerInterface $container, ResolverInterface $resolver): mixed
    {
        return $container->get($this->target);
    }

    public function toArray(): array
    {
        return $this->baseArray() + ['target' => $this->target];
    }
}
