<?php

/**
 * 文件功能：AI小班长钓鱼动作异步任务
 *
 * 模拟 AI 抛竿等待一定时间后收竿的过程。
 * 收竿时自动调用 FishingService 结算结果并播报。
 *
 * @author   ChatRoom Laravel
 *
 * @version  1.0.0
 */

namespace App\Jobs;

use App\Models\User;
use App\Services\FishingService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class AiFishingJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * @param  User  $aiUser  AI小班长
     * @param  int  $roomId  此事件广播的房间ID
     */
    public function __construct(
        public readonly User $aiUser,
        public readonly int $roomId,
    ) {}

    /**
     * 任务执行
     */
    public function handle(FishingService $fishingService): void
    {
        // 通过业务服务计算钓鱼结果并广播，标记 isAi 为 true
        $fishingService->processCatch($this->aiUser, $this->roomId, true);
    }
}
