<?php

declare(strict_types=1);

namespace Kylin\Agriculture\Models;

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

/**
 * 传感器数据模型
 *
 * 存储传感器采集的实时数据，如温度、湿度、光照等。
 *
 * @property float  $value      采集值
 * @property string $unit       单位
 * @property string $recorded_at 采集时间
 */
class SensorData extends Model
{
    public $timestamps = false;

    protected $table = 'kylin_agri_sensor_data';

    protected $fillable = [
        'sensor_id',
        'parameters',
        'collected_at',
        'created_at',
    ];

    protected function casts(): array
    {
        return [
            'parameters' => 'array',
            'collected_at' => 'datetime',
            'created_at' => 'datetime',
        ];
    }

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