<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('modpackchecker_servers', function (Blueprint $table) {
            $table->id();
            // Use the string UUID to match Pterodactyl's server identification
            $table->string('server_uuid')->unique();
            $table->string('platform')->nullable(); // curseforge, modrinth, technic, ftb
            $table->string('modpack_id')->nullable();
            $table->string('modpack_name')->nullable();
            $table->string('current_version')->nullable();
            $table->string('latest_version')->nullable();
            // Flexible string status instead of Enum for future extensibility
            $table->string('status')->default('unknown');
            $table->timestamp('last_checked')->nullable();
            $table->text('error_message')->nullable();
            $table->timestamps();

            // Foreign key - cascade delete when server is removed
            $table->foreign('server_uuid')->references('uuid')->on('servers')->onDelete('cascade');

            // Indexes for efficient lookups
            $table->index('status');
            $table->index('last_checked');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('modpackchecker_servers');
    }
};
