<?php
namespace Root\Core\Quantum;

class Superposition
{
    private array $states = [];

    public function addState(string $label, callable $generator): void
    {
        $this->states[$label] = $generator;
    }

    public function collapse(string $label): mixed
    {
        if (!isset($this->states[$label])) {
            throw new \RuntimeException("State not found");
        }
        $g = $this->states[$label];
        $val = $g();
        // replace with concrete value to avoid re-evaluation
        $this->states[$label] = fn() => $val;
        return $val;
    }
}
