<?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('personas_telefonos', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            
            $table->string('dni');
            $table->foreignId('persona_id')
                  ->constrained('personas')
                  ->onDelete('cascade');

            $table->foreignId('telefono_id')
                  ->constrained('telefonos')
                  ->onDelete('cascade');

            $table->unique(['dni','telefono_id'], 'personas_telefonos_unique');
        });
    }

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