<?php

namespace App\Events;

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

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

    public function __construct(public Quiz $quiz, public QuizQuestion $question, public array $topThree, public array $overall)
    {
    }

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

    public function broadcastAs(): string
    {
        return 'leaderboard.updated';
    }

    public function broadcastWith(): array
    {
        return [
            'question_id' => $this->question->id,
            'top_three' => $this->topThree,
            'overall' => $this->overall,
        ];
    }
}
