<?php

namespace Kylin\LawCase\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 案件状态流转模型
 *
 * 记录案件状态变更历史，包括流转前后状态、原因、审批人等。
 *
 * @property string $from_status  原状态
 * @property string $to_status    新状态
 * @property string $reason       变更原因
 */
class CaseStatusTransition extends Model
{
    protected $table = 'kylin_law_case_status_transitions';

    protected $fillable = [
        'case_id',
        'from_status',
        'to_status',
        'reason',
        'approved_by',
        'approved_at',
        'requested_by',
    ];

    protected $casts = [
        'approved_at' => 'datetime',
    ];

    public function case()
    {
        return $this->belongsTo(CaseModel::class);
    }

    public function approver()
    {
        return $this->belongsTo(\App\Models\User::class, 'approved_by');
    }

    public function requester()
    {
        return $this->belongsTo(\App\Models\User::class, 'requested_by');
    }
}
