<?php

require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/admin/config_.php';

use App\Pix\Sicoob;

$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$baseUrl = $scheme . '://' . $host;
$webhookUrl = 'https://undoing-poncho-jockstrap.ngrok-free.dev/webhook.php';

$objPix = new Sicoob();
$resultado = $objPix->registrarWebhook(SICOOBPIX_CHAVE, $webhookUrl);

header('Content-Type: application/json');
echo json_encode([
    'ok' => !empty($resultado['ok']) || ($resultado['httpCode'] ?? 0) >= 200 && ($resultado['httpCode'] ?? 0) < 300,
    'webhookUrl' => $webhookUrl,
    'resultado' => $resultado,
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
