<?php

namespace App\Models;

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

class ServerMetric extends Model
{
    use HasFactory;

    public $timestamps = false;

    protected $fillable = [
        'server_id', 'measured_at',
        'cpu', 'ram', 'disk',
        'load_1m', 'load_5m', 'load_15m',
        'net_in_mbps', 'net_out_mbps',
        'disk_io_read_mbps', 'disk_io_write_mbps',
        'processes', 'connections', 'extra',
    ];

    protected function casts(): array
    {
        return [
            'measured_at' => 'datetime',
            'cpu' => 'decimal:2',
            'ram' => 'decimal:2',
            'disk' => 'decimal:2',
            'extra' => 'array',
        ];
    }

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