<?php
declare(strict_types=1);

function kapvoe_env(string $key, ?string $default = null): string
{
    $value = getenv($key);
    if ($value === false || $value === '') {
        return $default ?? '';
    }
    return (string)$value;
}

$baseUrl = rtrim(kapvoe_env('KAPVOE_PUBLIC_BASE_URL', 'https://kapvoe-portfoli.treblarella.org'), '/');

return [
    'stripe_secret_key' => kapvoe_env('STRIPE_SECRET_KEY'),
    'stripe_webhook_secret' => kapvoe_env('STRIPE_WEBHOOK_SECRET'),

    'currency' => 'eur',
    'orders_storage_dir' => dirname(__DIR__) . '/data',

    'success_url' => $baseUrl . '/checkout/payment-success.php',
    'cancel_url' => $baseUrl . '/checkout/payment-cancel.php',

    'stock_sync_url' => kapvoe_env('KAPVOE_STOCK_SYNC_URL'),
    'stock_sync_token' => kapvoe_env('KAPVOE_STOCK_SYNC_TOKEN'),
    'catalog_api_url' => kapvoe_env('KAPVOE_CATALOG_API_URL', $baseUrl . '/api/products.php'),

    'analytics_enabled' => true,
    'analytics_sync_url' => kapvoe_env('KAPVOE_ANALYTICS_SYNC_URL'),
    'analytics_sync_token' => kapvoe_env('KAPVOE_ANALYTICS_SYNC_TOKEN'),
    'analytics_timeout' => 10,

    'mail_transport' => kapvoe_env('KAPVOE_MAIL_TRANSPORT', 'smtp'),
    'mail_from_email' => kapvoe_env('KAPVOE_MAIL_FROM_EMAIL', 'pedidos@bloodbros.store'),
    'mail_from_name' => kapvoe_env('KAPVOE_MAIL_FROM_NAME', 'Blood Bros Sports'),
    'mail_reply_to' => kapvoe_env('KAPVOE_MAIL_REPLY_TO', 'pedidos@bloodbros.store'),

    'resend_api_key' => kapvoe_env('KAPVOE_RESEND_API_KEY'),
    'resend_api_url' => kapvoe_env('KAPVOE_RESEND_API_URL', 'https://api.resend.com/emails'),

    'smtp_enabled' => true,
    'smtp_host' => kapvoe_env('KAPVOE_SMTP_HOST', 'mail.bloodbros.store'),
    'smtp_port' => (int)kapvoe_env('KAPVOE_SMTP_PORT', '587'),
    'smtp_encryption' => kapvoe_env('KAPVOE_SMTP_ENCRYPTION', 'tls'),
    'smtp_username' => kapvoe_env('KAPVOE_SMTP_USERNAME', 'pedidos@bloodbros.store'),
    'smtp_password' => kapvoe_env('KAPVOE_SMTP_PASSWORD'),
    'smtp_timeout' => 15,
    'smtp_allow_invalid_certificates' => true,

    'admin_notification_email' => kapvoe_env('KAPVOE_ADMIN_NOTIFICATION_EMAIL', 'pedidos@bloodbros.store'),

    'internal_notification_enabled' => true,
    'internal_notification_webhook_url' => kapvoe_env('KAPVOE_INTERNAL_NOTIFICATION_WEBHOOK_URL'),
    'internal_notification_webhook_token' => kapvoe_env('KAPVOE_INTERNAL_NOTIFICATION_WEBHOOK_TOKEN'),
    'internal_notification_timeout' => 10,
    'internal_notification_log_path' => dirname(__DIR__) . '/data/internal-notifications.log',

    'admin_tools_token' => kapvoe_env('KAPVOE_ADMIN_TOOLS_TOKEN'),
];