<?php

namespace Kylin\LawCase\Listeners;

use Kylin\LawCase\Events\CaseStatusChanged;
use Kylin\LawCase\Jobs\SendCaseNotification as SendCaseNotificationJob;

/**
 * 发送案件通知监听器
 *
 * 监听案件状态变更事件，异步发送通知。
 */
class SendCaseNotification
{
    public function handle(CaseStatusChanged $event): void
    {
        $case = $event->case;
        $message = "案件状态变更：{$event->oldStatus->label()} → {$event->newStatus->label()}";

        // 通知主办律师
        if ($case->principalLawyer) {
            SendCaseNotificationJob::dispatch(
                $case->principalLawyer,
                $case,
                $message
            );
        }

        // 通知律师助理
        if ($case->assistantLawyer) {
            SendCaseNotificationJob::dispatch(
                $case->assistantLawyer,
                $case,
                $message
            );
        }
    }
}
