<?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 InstanceDefinition extends AbstractDefinition
{
    public function __construct(string $id, private readonly object $instance)
    {
        parent::__construct($id, Lifetime::INSTANCE);
    }

    public function type(): string { return DefinitionType::INSTANCE_SERVICE; }
    public function instance(): object { return $this->instance; }

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

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