<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Str;

class Server extends Model
{
    protected $guarded = [];

    protected $casts = [
        'specs' => 'array',
        'last_seen_at' => 'datetime',
    ];

    protected static function booted(): void
    {
        static::creating(fn (self $s) => $s->uuid ??= (string) Str::uuid());
    }

    // R11: URLs address servers by uuid, never the bigint id.
    public function getRouteKeyName(): string
    {
        return 'uuid';
    }

    public function credential(): HasOne
    {
        return $this->hasOne(SshCredential::class);
    }
}
