<?php
namespace Root\Core\Obscura;

class Parallax
{
    private array $layers = [];

    public function attach(callable $c, int $priority = 10): void
    {
        $this->layers[$priority][] = $c;
        ksort($this->layers);
    }

    public function dispatch(mixed $payload): mixed
    {
        $result = $payload;
        foreach ($this->layers as $prio => $callables) {
            foreach ($callables as $cb) {
                $result = $cb($result, $prio);
            }
        }
        return $result;
    }
}
