<?php

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

/**
 * PRC-1143 — konsolide şema: `ip_pools` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('ip_pools', function (Blueprint $t) {
            $t->id();
            $t->string('name', 120);
            $t->unsignedBigInteger('server_id');
            $t->string('cidr', 18);
            $t->string('gateway', 15)->nullable();
            $t->string('network', 15)->nullable();
            $t->string('broadcast', 15)->nullable();
            $t->string('allocator', 32)->default('sequential');
            $t->unsignedSmallInteger('quarantine_days')->default(7);
            $t->boolean('is_default')->default(0);
            $t->text('notes')->nullable();
            $t->boolean('is_active')->default(1);
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index(['server_id', 'is_active'], 'ip_pools_server_id_is_active_index');
            $t->index(['server_id', 'is_default'], 'ip_pools_server_id_is_default_index');
            $t->foreign('server_id', 'ip_pools_server_id_foreign')->references('id')->on('servers')->onDelete('cascade');
        });
    }

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