<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePreoccupationsTable extends Migration
{
    public function up()
    {
        Schema::create('preoccupations', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('etablissement_id')->nullable();
            $table->unsignedBigInteger('module_id');
            $table->unsignedBigInteger('progiciel_id');
            $table->unsignedBigInteger('priorite_id')->nullable();
            $table->text('description');
            $table->dateTime('date_soumission');
            $table->dateTime('date_debut')->nullable();
            $table->dateTime('date_fin')->nullable();
            $table->integer('dure_resolution')->nullable();
            $table->json('media_paths')->nullable()->after('description'); // Colonne pour stocker les fichiers
            $table->text('methodeResol');
            $table->unsignedBigInteger('statut_id');
            $table->timestamps();

            $table->foreign('etablissement_id')->references('id')->on('etablissements')->onDelete('set null');
            $table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade');
            $table->foreign('progiciel_id')->references('id')->on('progiciels')->onDelete('cascade');
            $table->foreign('priorite_id')->references('id')->on('priorites')->onDelete('set null');
            $table->foreign('statut_id')->references('id')->on('statuts')->onDelete('cascade');
        });
    }

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