<?php

use App\Tenancy\TenantManager;
use Illuminate\Support\Facades\Broadcast;

/**
 * Tenant-scoped private channels: only users belonging to the current tenant
 * can subscribe. Channel name encodes the tenant slug.
 */
Broadcast::channel('tenant.{slug}', function ($user, string $slug) {
    $tenant = app(TenantManager::class)->current();
    return $tenant && $tenant->slug === $slug && (int) $user->company_id === (int) $tenant->id;
});
