<?php
require_once __DIR__.'/../../_bootstrap.php';require_once ROOT_PATH.'/includes/match_functions.php';
if($_SERVER['REQUEST_METHOD']!=='POST')jsonResponse(['ok'=>false,'erro'=>'Método não permitido.'],405);afValidarCsrfApi();$u=afApiOuSessaoUsuario($pdo);$d=requestJson();$target=(int)($d['user_id']??0);$action=(string)($d['action']??'block');
try{if($action==='unblock')afModerationUnblockUser($pdo,(int)$u['id'],$target);else afModerationBlockUser($pdo,(int)$u['id'],$target,'user',null,(string)($d['reason']??''));jsonResponse(['ok'=>true,'blocked'=>$action!=='unblock']);}
catch(Throwable $e){jsonResponse(['ok'=>false,'erro'=>$e->getMessage()],422);}
