<?php

// Load from .env file if present (not committed to git)
$envFile = __DIR__ . '/../.env';
if (file_exists($envFile)) {
    foreach (file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
        if (str_starts_with(trim($line), '#')) continue;
        if (strpos($line, '=') === false) continue;
        [$k, $v] = explode('=', $line, 2);
        putenv(trim($k) . '=' . trim($v));
    }
}

define('SUPABASE_URL', getenv('SUPABASE_URL') ?: 'https://safe-supabase-kong.caprover.al-arcade.com');
define('SUPABASE_ANON_KEY', getenv('SUPABASE_ANON_KEY') ?: '');
define('SUPABASE_SERVICE_KEY', getenv('SUPABASE_SERVICE_KEY') ?: '');
// Signing secret for Supabase-issued JWTs. When set, api requests verify tokens
// in-process instead of calling GoTrue on every single request — which matters a
// great deal when every live game polls twice a second.
define('SUPABASE_JWT_SECRET', getenv('SUPABASE_JWT_SECRET') ?: '');

define('SUPABASE_REST', SUPABASE_URL . '/rest/v1');
define('SUPABASE_AUTH', SUPABASE_URL . '/auth/v1');
define('SUPABASE_STORAGE', SUPABASE_URL . '/storage/v1');
define('STOCKFISH_API', getenv('STOCKFISH_API') ?: 'https://stockfishapi.caprover.al-arcade.com');
define('SWISS_API', getenv('SWISS_API') ?: 'https://swissapi.caprover.al-arcade.com/api/v1');
// The external Swiss service rejects every unauthenticated request. EL3AB now
// runs its own pairing engine, so this is optional: set it only to mirror a
// tournament out to that service as well.
define('SWISS_API_KEY', getenv('SWISS_API_KEY') ?: '');

// Shared secret for api/cron.php (auto-start, no-show forfeits, stale cleanup).
define('CRON_SECRET', getenv('CRON_SECRET') ?: '');
