<?php

namespace App\Models;

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

class Port extends Model
{
    use HasFactory;

    protected $fillable = [
        'server_id', 'label', 'protocol', 'port', 'service_type',
        'expect_banner', 'expected_banner_pattern',
        'status', 'last_latency_ms', 'last_banner', 'last_checked_at',
        'is_active', 'alerts_enabled',
    ];

    protected $casts = [
        'expect_banner' => 'boolean',
        'is_active' => 'boolean',
        'alerts_enabled' => 'boolean',
        'last_checked_at' => 'datetime',
    ];

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

    public function incidents(): MorphMany
    {
        return $this->morphMany(Incident::class, 'subject');
    }
}
