<?php

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

return new class extends Migration
{
    /**
     * Rulează migrarea - creează tabela pentru istoricul actualizărilor DynDNS
     */
    public function up(): void
    {
        Schema::create('dynamic_dns_update_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('dynamic_dns_client_id')->constrained('dynamic_dns_clients')->onDelete('cascade');
            $table->string('old_ip', 45)->nullable(); // Suport IPv6
            $table->string('new_ip', 45);
            $table->string('request_ip', 45)->nullable(); // IP-ul de unde a venit request-ul
            $table->string('user_agent')->nullable(); // User agent (script bash, powershell, etc)
            $table->enum('status', ['success', 'error', 'nochg'])->default('success'); // nochg = IP nu s-a schimbat
            $table->text('message')->nullable(); // Mesaj de eroare sau succes
            $table->timestamps();

            // Index pentru căutări rapide
            $table->index(['dynamic_dns_client_id', 'created_at']);
        });
    }

    /**
     * Reversează migrarea
     */
    public function down(): void
    {
        Schema::dropIfExists('dynamic_dns_update_logs');
    }
};
