<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        //
    }

    public function boot(): void
    {
        if ($this->shouldDisablePusher()) {
            config(['broadcasting.default' => 'null']);
        }
    }

    /**
     * Placeholder Pusher keys in .env must not break API writes (entries, units, etc.).
     */
    private function shouldDisablePusher(): bool
    {
        if (config('broadcasting.default') !== 'pusher') {
            return false;
        }

        $key = (string) config('broadcasting.connections.pusher.key', '');

        return $key === ''
            || str_starts_with($key, 'your_')
            || $key === 'your_pusher_app_key';
    }
}
