<?php

namespace Kylin\LawCase\Jobs;

use App\Models\User;
use Kylin\LawCase\Models\CaseModel;
use Kylin\LawCase\Notifications\CaseStatusChangedNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

/**
 * 案件通知 Job
 *
 * 异步发送案件状态变更通知。
 */
class SendCaseNotification implements ShouldQueue
{
    use InteractsWithQueue, Queueable;

    public int $tries = 3;
    public int $timeout = 60;

    public function __construct(
        public User $user,
        public CaseModel $case,
        public string $message
    ) {}

    public function handle(): void
    {
        Log::info("案件通知: 用户{$this->user->id}, 案件{$this->case->case_no}, 消息: {$this->message}");

        // 发送站内信通知
        $this->user->notify(new CaseStatusChangedNotification($this->case, $this->message));
    }
}
