<?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('dns_statistics', function (Blueprint $table) {
            $table->id();
            $table->foreignId('dns_zone_id')->constrained()->onDelete('cascade');
            $table->date('date');
            $table->unsignedBigInteger('query_count')->default(0);
            $table->json('query_types')->nullable(); // A, AAAA, MX, etc.
            $table->json('response_codes')->nullable(); // NOERROR, NXDOMAIN, etc.
            $table->json('top_clients')->nullable(); // Top IP-uri care fac query-uri
            $table->timestamps();
            
            // Index pentru căutări rapide
            $table->index(['dns_zone_id', 'date']);
            $table->unique(['dns_zone_id', 'date']); // O singură înregistrare pe zi per zonă
        });
    }

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