<?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('projects', function (Blueprint $table) {
            $table->id();
            $table->foreignId('speerpunt_id')->nullable()->constrained('speerpunten')->nullOnDelete();
            $table->string('naam');
            $table->text('beschrijving');
            $table->foreignId('eigenaar_id')->constrained('users')->restrictOnDelete();
            $table->enum('status', [
                'signaal',
                'verkenning',
                'concept',
                'experiment',
                'pilot',
                'besluitvorming',
                'overdracht_bouwen',
                'overdracht_beheer',
                'evaluatie',
                'geparkeerd',
                'gestopt',
                'afgerond',
            ])->default('signaal');
            $table->enum('prioriteit', ['laag', 'midden', 'hoog'])->default('midden');
            $table->date('startdatum')->nullable();
            $table->date('streef_einddatum')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('project_user', function (Blueprint $table) {
            $table->foreignId('project_id')->constrained()->cascadeOnDelete();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->enum('rol', ['eigenaar', 'lid', 'reviewer', 'stakeholder'])->default('lid');
            $table->timestamps();
            $table->primary(['project_id', 'user_id']);
        });
    }

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