<?php

$sandbox = filter_var(env('PADDLE_SANDBOX', false), FILTER_VALIDATE_BOOLEAN);

$environment = env('PADDLE_ENVIRONMENT', $sandbox ? 'sandbox' : 'production');

$apiKey = env('PADDLE_API_KEY') ?: env('PADDLE_SANDBOX_API_KEY');

$clientToken = $sandbox
    ? (env('PADDLE_SANDBOX_CLIENT_TOKEN') ?: env('PADDLE_SANDBOX_CLIENT_ID') ?: env('PADDLE_CLIENT_TOKEN') ?: env('PADDLE_CLIENT_ID'))
    : (env('PADDLE_CLIENT_TOKEN') ?: env('PADDLE_CLIENT_ID'));

$webhookSecret = env('PADDLE_WEBHOOK_SECRET') ?: ($sandbox ? env('PADDLE_SANDBOX_WEBHOOK_SECRET') : null);

$publicKey = env('PADDLE_PUBLIC_KEY') ?: ($sandbox ? env('PADDLE_SANDBOX_PUBLIC_KEY') : null);

$baseUrl = env('PADDLE_BASE_URL');
if (! $baseUrl) {
    $baseUrl = $sandbox ? 'https://sandbox-api.paddle.com' : 'https://api.paddle.com';
}

$consoleUrl = env('PADDLE_CONSOLE_URL');
if (! $consoleUrl) {
    $consoleUrl = $sandbox ? 'https://sandbox-dashboard.paddle.com' : 'https://dashboard.paddle.com';
}

return [
    'api_key' => $apiKey,
    'client_token' => $clientToken,
    'environment' => $environment,
    'base_url' => $baseUrl,
    'console_url' => $consoleUrl,
    'webhook_secret' => $webhookSecret,
    'public_key' => $publicKey,
    'webhook_events' => [
        'transaction.created',
        'transaction.processing',
        'transaction.completed',
        'transaction.failed',
        'transaction.cancelled',
        'subscription.created',
        'subscription.updated',
        'subscription.paused',
        'subscription.resumed',
        'subscription.cancelled',
        'subscription.past_due',
    ],
];
