<?php

// ============================================
// CARREGA .ENV
// ============================================

$envFile = __DIR__ . '/../.env';

date_default_timezone_set('America/Sao_Paulo');

if (file_exists($envFile)) {
    $lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach ($lines as $line) {
        if (strpos(trim($line), '#') === 0) {
            continue;
        }
        
        if (strpos($line, '=') !== false) {
            list($key, $value) = explode('=', $line, 2);
            $key = trim($key);
            $value = trim($value);
            $value = trim($value, '"\'');
            
            putenv("{$key}={$value}");
            $_ENV[$key] = $value;
            $_SERVER[$key] = $value;
        }
    }
}

// ============================================
// CONFIGURAÇÕES
// ============================================

define('BASE_URL', getenv('BASE_URL') ?: 'https://mailsendercentre.newerasolutions.com.br');
define('DEFAULT_TOKEN_EXPIRATION_DAYS', 15);
define('UPLOAD_PATH', __DIR__ . '/../../storage');

// SENDGRID
define('SENDGRID_API_KEY', getenv('SENDGRID_API_KEY'));
define('SENDGRID_FROM_EMAIL', getenv('SENDGRID_FROM_EMAIL'));
define('SENDGRID_FROM_NAME', getenv('SENDGRID_FROM_NAME'));

// Validações
if (!SENDGRID_API_KEY) {
    error_log('WARNING: SENDGRID_API_KEY not configured');
}

if (!SENDGRID_FROM_EMAIL) {
    error_log('WARNING: SENDGRID_FROM_EMAIL not configured');
}