<?php
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');

if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit;
}

date_default_timezone_set('America/Guatemala');

function getConnection() {
    static $pdo = null;
    if ($pdo === null) {
        $config = require dirname(__DIR__, 2) . '/db_config.php';
        require_once dirname(__DIR__, 2) . '/dual_pdo.php';
        $pdo = getDualConnection($config);
        $pdo->exec("SET time_zone = '-06:00'");
    }
    return $pdo;
}
