<?php

namespace Modules\LabCore\Entities;

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

class LabDeviceError extends Model
{
    protected $table = 'lab_device_errors';

    protected $fillable = [
        'agent_id', 'device_id', 'vendor', 'error_code', 'error_date',
        'error_time', 'message', 'added_info', 'device_ip',
        'acknowledged', 'acknowledged_at', 'acknowledged_by',
    ];

    protected $casts = [
        'added_info'      => 'array',
        'error_date'      => 'date',
        'acknowledged'    => 'boolean',
        'acknowledged_at' => 'datetime',
    ];

    public function device(): BelongsTo
    {
        return $this->belongsTo(LabDevice::class, 'device_id');
    }

    public function scopeUnacknowledged($query)
    {
        return $query->where('acknowledged', false);
    }
}
