<?php
declare(strict_types=1);
function nfBudgetTake(string $kind,int $cap): int {
    $f=__DIR__.'/private/'.$kind.'-budget.json';$h=fopen($f,'c+');if(!$h||!flock($h,LOCK_EX))throw new RuntimeException('Budget lock');$raw=stream_get_contents($h);$r=$raw===''?['count'=>0]:json_decode($raw,true);if($r['count']>=$cap){flock($h,LOCK_UN);fclose($h);throw new RuntimeException('Exact '.$kind.' cap');}$r['count']++;rewind($h);ftruncate($h,0);fwrite($h,json_encode($r));fflush($h);flock($h,LOCK_UN);fclose($h);chmod($f,0600);return $r['count'];
}
final class NFObserverBudget { public static function take(): int {return nfBudgetTake('observer',208);} }
