<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

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

    public function __construct(
        public string $taskId,
        public string $kpCode,
        public int $total
    ) {}

    public function broadcastOn(): Channel
    {
        return new Channel('question-gen.' . $this->taskId);
    }

    public function broadcastAs(): string
    {
        return 'QuestionGenerationCompleted';
    }

    public function broadcastWith(): array
    {
        return [
            'task_id' => $this->taskId,
            'kp_code' => $this->kpCode,
            'total' => $this->total,
            'message' => '题目生成完成',
        ];
    }
}
