<?php

namespace App\Broadcasting\Entity;

final readonly class WebsocketEventData
{
    public function __construct(
        public string  $room,
        public mixed   $data,
        public string  $event       = 'event',
        public ?string $projectName = null
    ) {}

    public static function from(
        string $room,
        mixed  $data,
        string $event = 'event'
    ): self {
        return new self(
            room:        $room,
            data:        $data,
            event:       $event,
            projectName: config('app.name')
        );
    }

    public function channelName(): string
    {
        return "{$this->projectName}:{$this->room}@{$this->event}";
    }
}
