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

            // Foreign keys
            $table->unsignedBigInteger('parent_profile_id');
            $table->unsignedBigInteger('student_profile_id');

            $table->foreign('parent_profile_id')
                ->references('id')->on('parent_profiles')
                ->onDelete('cascade');

            $table->foreign('student_profile_id')
                ->references('id')->on('student_profiles')
                ->onDelete('cascade');

            // Optional descriptive relationship
            $table->string('relationship')->nullable();

            // Optional admin notes
            $table->text('notes')->nullable();

            $table->timestamps();

            // Ensure a parent cannot be linked to the same student twice
            $table->unique(['parent_profile_id', 'student_profile_id']);
        });
    }

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