<?php

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

/**
 * Holds the SSH login for the "Clusev host" terminal — a single row (the host is one machine).
 * Unlike a fleet server, the host is not in the `servers` table; the operator stores its root
 * (or any) login here so the terminal sidecar can SSH into the actual host instead of opening a
 * shell inside its own container. The secret/passphrase are encrypted at rest (model casts).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('host_credentials', function (Blueprint $table) {
            $table->id();
            // Reachable from the terminal sidecar container; defaults to the docker host gateway.
            $table->string('host')->default('host.docker.internal');
            $table->unsignedSmallInteger('port')->default(22);
            $table->string('username')->default('root');
            $table->string('auth_type')->default('password'); // 'password' | 'key'
            $table->text('secret');                            // encrypted (password or private key)
            $table->text('passphrase')->nullable();            // encrypted (key passphrase)
            $table->timestamps();
        });
    }

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