<?php

declare(strict_types=1);

namespace Kylin\Agriculture\Models;

use Illuminate\Database\Eloquent\Model;
use Kylin\Agriculture\Enums\WarningLevel;

/**
 * 预警规则模型
 *
 * 定义传感器预警规则，包括参数、运算符、阈值、预警等级等。
 *
 * @property string $name      规则名称
 * @property string $parameter 监控参数
 * @property string $operator  比较运算符
 * @property float  $threshold 阈值
 * @property string $level     预警等级
 */
class WarningRule extends Model
{
    protected $table = 'kylin_agri_warning_rules';

    protected $fillable = [
        'name',
        'parameter',
        'operator',
        'threshold',
        'level',
        'enabled',
    ];

    protected function casts(): array
    {
        return [
            'threshold' => 'decimal:2',
            'level' => WarningLevel::class,
            'enabled' => 'boolean',
        ];
    }
}
