<?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_zone_assignments', function (Blueprint $table) {
            $table->id();
            $table->string('zone_name'); // numele zonei (ex: back.ro)
            $table->foreignId('user_id')->constrained()->onDelete('cascade'); // utilizatorul asignat
            $table->enum('access_level', ['full', 'records_only'])->default('full'); // nivel acces: complet sau doar records
            $table->timestamp('assigned_at')->useCurrent();
            $table->foreignId('assigned_by')->constrained('users'); // cine a făcut atribuirea
            $table->timestamps();

            // Index pentru performanță
            $table->unique(['zone_name', 'user_id']);
            $table->index('zone_name');
            $table->index('user_id');
        });
    }

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