<?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 ValueDefinition extends AbstractDefinition
{
    public function __construct(string $id, private readonly mixed $value)
    {
        parent::__construct($id, Lifetime::VALUE);
    }

    public function type(): string { return DefinitionType::VALUE_SERVICE; }
    public function value(): mixed { return $this->value; }

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

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