<?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 ClassDefinition extends AbstractDefinition
{
    public function __construct(string $id, private readonly string $className, string $lifetime = Lifetime::TRANSIENT)
    {
        parent::__construct($id, $lifetime);
    }

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

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

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