<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel; // Importante para segurança
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class DashboardUpdate implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $tenantId;

    // Recebemos o ID da empresa que sofreu alteração
    public function __construct($tenantId)
    {
        $this->tenantId = $tenantId;
    }

    // Define o canal privado: "dashboard.{tenant_id}"
    public function broadcastOn(): array
    {
        return [
            new PrivateChannel('dashboard.' . $this->tenantId),
        ];
    }
    
    // Opcional: Nome do evento no Front (padrão é o nome da classe)
    public function broadcastAs()
    {
        return 'metrics.updated';
    }
}