<?php

namespace App\Broadcasting\Events;

use App\Broadcasting\Entity\WebsocketEventData;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

final class WebsocketEvent implements ShouldBroadcastNow, WebsocketEventInterface
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(
        private readonly WebsocketEventData $dto
    ) {}

    public function broadcastOn(): Channel
    {
        return new Channel($this->dto->channelName());
    }

    public function broadcastWith(): array
    {
        return ['data' => $this->dto->data];
    }
}
