<?php

namespace App\Events;

use App\Models\Quiz;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class QuizStarted implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(public Quiz $quiz)
    {
    }

    public function broadcastOn(): array
    {
        return [new Channel('quiz.'.$this->quiz->uuid)];
    }

    public function broadcastAs(): string
    {
        return 'quiz.started';
    }

    public function broadcastWith(): array
    {
        return [
            'quiz' => [
                'uuid' => $this->quiz->uuid,
                'title' => $this->quiz->title,
                'status' => $this->quiz->status,
            ],
        ];
    }
}
