<?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 QuestionGenerationFailed implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

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

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

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

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