<?php

require __DIR__ . '/../vendor/autoload.php';

use FrameworkX\App;

if (class_exists(Dotenv\Dotenv::class) && file_exists(__DIR__ . '/../.env')) {
    Dotenv\Dotenv::createImmutable(
        dirname(__DIR__),
        null,
        true
    )->safeLoad();
}
//webhook teste push
error_reporting(E_ALL);

$dsn = $_ENV['DB_DSN'] ?? (function () {
    $host = $_ENV['DB_HOST'] ?? 'localhost';
    $port = $_ENV['DB_PORT'] ?? '5432';
    $name = $_ENV['DB_NAME'] ?? 'postgres';
    return "pgsql:host={$host};port={$port};dbname={$name}";
})();
$dbUser = $_ENV['DB_USER'] ?? 'postgres';
$dbPass = $_ENV['DB_PASSWORD'] ?? '';
$GLOBALS['pdo'] = new \PDO($dsn, $dbUser, $dbPass);
$GLOBALS['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

$app = new App();

$app->post('/tshield', \Controllers\TshieldWebhookController::class);
$app->post('/woovi', \Controllers\WooviWebhookController::class);

$app->run();