<?php

namespace Kylin\LawCase\Listeners;

use Kylin\LawCase\Events\CaseStatusChanged;
use Kylin\LawCase\Models\CaseMilestone;

/**
 * 记录状态变更监听器
 *
 * 监听案件状态变更事件，记录里程碑。
 */
class RecordStatusChange
{
    public function handle(CaseStatusChanged $event): void
    {
        CaseMilestone::create([
            'case_id' => $event->case->id,
            'milestone_type' => 'status_change',
            'milestone_date' => now()->toDateString(),
            'description' => "状态从{$event->oldStatus->label()}变更为{$event->newStatus->label()}"
                . ($event->reason ? "：{$event->reason}" : ''),
        ]);
    }
}
