<?php
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/entity.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') json_error('Método no permitido.', 405);

$wantsAll = ($_GET['all'] ?? '') === '1';
if ($wantsAll) require_admin($config);

// The admin list (all=1) shows every language at once; the public site always
// asks for one. An explicit ?lang= still narrows the admin list if wanted.
$lang = isset($_GET['lang']) ? entity_lang($_GET['lang']) : ($wantsAll ? null : ENTITY_DEFAULT_LANG);

json_ok(['posts' => entity_list($pdo, 'posts', $wantsAll, $lang)]);
