<?php

/*
 * Broadcasting connections.
 *
 * The DEFAULT connection is intentionally pointed at `null` here. The
 * AppServiceProvider boots logic that flips it to 'pusher' at runtime
 * when the admin has saved valid Pusher credentials AND enabled the
 * `integration_pusher_enabled` toggle. That way:
 *   - A fresh install with no Pusher config doesn't spam the queue with
 *     broadcasting attempts that go nowhere.
 *   - As soon as admin pastes keys + flips the toggle, the next request
 *     hot-swaps the broadcaster — no server restart needed.
 *   - Pusher keys come from system_settings (admin → Settings → Integrations),
 *     not just env, so the customer never has to SSH-edit .env.
 *
 * .env can still set BROADCAST_CONNECTION explicitly to override.
 */

return [
    'default' => env('BROADCAST_CONNECTION', 'null'),

    'connections' => [
        'pusher' => [
            'driver' => 'pusher',
            'key'    => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster'   => env('PUSHER_APP_CLUSTER', 'mt1'),
                'host'      => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com',
                'port'      => env('PUSHER_PORT', 443),
                'scheme'    => env('PUSHER_SCHEME', 'https'),
                'encrypted' => true,
                'useTLS'    => env('PUSHER_SCHEME', 'https') === 'https',
            ],
            'client_options' => [
                // Stripe-style throttle so a runaway loop can't burst the
                // Pusher account's quota in seconds.
                'timeout' => 10,
            ],
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],
    ],
];
