<?php
declare(strict_types=1);
require __DIR__.'/peer_sync_lib.php';
if (PHP_SAPI !== 'cli') { method('POST'); require_auth(true); }
try { $result=peer_sync_once($config); if(PHP_SAPI==='cli'){echo json_encode($result,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES).PHP_EOL;exit(0);} respond($result); }
catch(SiapaPeerException $e){ if(PHP_SAPI==='cli'){fwrite(STDERR,json_encode(array_merge(['error'=>$e->getMessage()],$e->details),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES).PHP_EOL);exit($e->httpStatus===409?2:1);} respond(array_merge(['error'=>$e->getMessage()],$e->details),$e->httpStatus); }
catch(Throwable $e){ if(PHP_SAPI==='cli'){fwrite(STDERR,json_encode(['error'=>$e->getMessage()],JSON_UNESCAPED_UNICODE).PHP_EOL);exit(1);} respond(['error'=>'Error interno de réplica.'],500); }
