<?php
require_once __DIR__.'/../../_bootstrap.php';require_once ROOT_PATH.'/includes/match_functions.php';$u=afApiOuSessaoUsuario($pdo,'competition');$id=max(0,(int)($_GET['id']??0));$c=afBuscarCompeticao($pdo,$id);if(!$c)jsonResponse(['ok'=>false,'erro'=>'Competição não encontrada.'],404);if($c['visibilidade']==='privado'&&(int)$c['criador_id']!==(int)$u['id']){$st=$pdo->prepare('SELECT id FROM af_competicao_participantes WHERE competicao_id=? AND usuario_id=? LIMIT 1');$st->execute([$id,(int)$u['id']]);if(!$st->fetchColumn())jsonResponse(['ok'=>false,'erro'=>'Competição privada.'],403);}jsonResponse(['ok'=>true,'competicao'=>afCompeticaoPublica($pdo,$c,(int)$u['id'])]);
