<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('hosts', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->string('name');
            $table->string('datacenter');                 // placement filter, e.g. fsn, hel
            $table->string('cluster')->nullable();        // v1.0 always null (growth goal)
            $table->string('public_ip');                  // first SSH login
            $table->string('wg_ip')->nullable();          // management address (Proxmox API)
            $table->string('wg_pubkey')->nullable();      // host WG peer public key
            $table->text('ssh_host_key')->nullable();     // fingerprint pinning
            $table->text('api_token_ref')->nullable();    // encrypted: automation@pve!<id>=<secret>
            $table->unsignedBigInteger('total_gb')->nullable();
            $table->unsignedBigInteger('total_ram_mb')->nullable();
            $table->unsignedInteger('cpu_cores')->nullable();
            $table->unsignedInteger('cpu_weight')->nullable();
            $table->unsignedInteger('reserve_pct')->default(15);
            $table->string('pve_version')->nullable();
            $table->string('status')->default('pending'); // pending, onboarding, active, error, disabled
            $table->timestamp('last_seen_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('hosts');
    }
};
