<?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('ip_pools', function (Blueprint $table) {
            $table->id();
            $table->string('name', 120);
            $table->foreignId('server_id')->constrained()->cascadeOnDelete();
            $table->string('cidr', 18);
            $table->string('gateway', 15)->nullable();
            $table->string('network', 15)->nullable();
            $table->string('broadcast', 15)->nullable();
            $table->string('allocator', 32)->default('sequential');
            $table->unsignedSmallInteger('quarantine_days')->default(7);
            $table->boolean('is_default')->default(false);
            $table->text('notes')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();

            $table->index(['server_id', 'is_active']);
            $table->index(['server_id', 'is_default']);
        });
    }

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