<?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('terminal_sessions', function (Blueprint $table) {
            $table->id();
            $table->string('token', 64)->unique();      // single-use handle the sidecar exchanges for a connection spec
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('kind');                       // 'server' | 'host'
            $table->foreignId('server_id')->nullable()->constrained()->cascadeOnDelete();
            $table->timestamp('expires_at')->index();     // short TTL to connect
            $table->timestamp('used_at')->nullable();     // burned on first resolve (single use)
            $table->timestamp('created_at')->nullable();
        });
    }

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