<?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('lessons_learned', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->nullable()->constrained('projects')->nullOnDelete();
            $table->foreignId('fase_id')->nullable()->constrained('fases')->nullOnDelete();
            $table->string('titel');
            $table->text('inhoud');
            $table->timestamps();
        });

        Schema::create('lesson_learned_tag', function (Blueprint $table) {
            $table->foreignId('lesson_learned_id')->constrained('lessons_learned')->cascadeOnDelete();
            $table->foreignId('tag_id')->constrained()->cascadeOnDelete();
            $table->primary(['lesson_learned_id', 'tag_id']);
        });
    }

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