<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type, Authorization');

require_once __DIR__ . '/../../config.php';

$headers    = getallheaders();
$authHeader = $headers['Authorization'] ?? $headers['authorization'] ?? '';
$token      = str_replace('Bearer ', '', $authHeader);
if (empty($token)) { http_response_code(401); echo json_encode(['error'=>'no token']); exit; }
$db  = getDB();
$now = date('Y-m-d H:i:s');
$s = $db->prepare("SELECT idusuarios_sist FROM admin_sessions WHERE token=? AND expira>? LIMIT 1");
$s->execute([$token, $now]);
if (!$s->fetch()) { http_response_code(401); echo json_encode(['error'=>'invalid']); exit; }

// Ver columnas de la tabla pedido
$cols = $db->query("DESCRIBE pedido")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['success'=>true, 'pedido_columns'=>$cols], JSON_UNESCAPED_UNICODE);
