<?php

namespace App\Models;

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

class MonitoringTarget extends Model
{
    protected $fillable = ['instance_id', 'external_id', 'url', 'status', 'checked_at'];

    protected function casts(): array
    {
        // Without the cast the freshness comparison happens between a string
        // and a Carbon instance, and without checked_at being fillable the sync
        // job's update silently drops it — leaving every verdict permanently
        // stale, which reads on the status page as "not monitored".
        return ['checked_at' => 'datetime'];
    }

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