<?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('aluno_responsaveis', function (Blueprint $table) {
            $table->id();

            $table->foreignId('aluno_id')
                ->constrained('alunos')
                ->cascadeOnDelete();

            $table->foreignId('user_id') // responsável (users)
                ->constrained('users')
                ->cascadeOnDelete();

            $table->timestamps();

            // impede duplicar o mesmo responsável no mesmo aluno
            $table->unique(['aluno_id', 'user_id']);
        });
    }

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