<?php

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

/**
 * PRC-1143 — konsolide şema: `ip_pool_imports` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('ip_pool_imports', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('pool_id');
            $t->string('cidr', 18)->nullable();
            $t->enum('source', ['cidr','range','manual','manual_legacy']);
            $t->unsignedInteger('total_count')->default(0);
            $t->unsignedInteger('free_count')->default(0);
            $t->unsignedInteger('reserved_count')->default(0);
            $t->unsignedBigInteger('imported_by_admin_id')->nullable();
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index('imported_by_admin_id', 'ip_pool_imports_imported_by_admin_id_foreign');
            $t->index('pool_id', 'ip_pool_imports_pool_id_index');
            $t->foreign('imported_by_admin_id', 'ip_pool_imports_imported_by_admin_id_foreign')->references('id')->on('admins')->onDelete('set null');
            $t->foreign('pool_id', 'ip_pool_imports_pool_id_foreign')->references('id')->on('ip_pools')->onDelete('cascade');
        });
    }

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