<?php

namespace Kylin\Logistics\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * 温度记录模型
 *
 * 记录冷链运输过程中的温度传感器数据。
 *
 * @property float  $temp        温度值
 * @property bool   $is_abnormal 是否异常
 * @property string $recorded_at 记录时间
 */
class TempRecord extends Model
{
    public $timestamps = false;

    protected $table = 'kylin_log_temp_records';

    protected $fillable = [
        'waybill_id', 'sensor_id', 'temp', 'is_abnormal', 'recorded_at',
    ];

    protected $casts = [
        'temp' => 'decimal:4,1',
        'is_abnormal' => 'boolean',
        'recorded_at' => 'datetime',
    ];

    public function waybill(): BelongsTo
    {
        return $this->belongsTo(Waybill::class);
    }
}
