<?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::table('tareas', function (Blueprint $table) {
            $table->string('titulo');
            $table->text('descripcion')->nullable();
            $table->date('fecha_entrega')->nullable();
            $table->unsignedBigInteger('material_id');
            $table->unsignedBigInteger('grupo_id');
            $table->unsignedBigInteger('docente_id');

            $table->foreign('material_id')->references('id')->on('materials')->onDelete('cascade');
            $table->foreign('grupo_id')->references('id')->on('grupos')->onDelete('cascade');
            $table->foreign('docente_id')->references('id')->on('docentes')->onDelete('cascade');
        });
    }

    public function down(): void
    {
        Schema::table('tareas', function (Blueprint $table) {
            $table->dropForeign(['material_id']);
            $table->dropForeign(['grupo_id']);
            $table->dropForeign(['docente_id']);
            $table->dropColumn(['titulo', 'descripcion', 'fecha_entrega', 'material_id', 'grupo_id', 'docente_id']);
        });
    }
};
