<?php

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

class CreateSujesTableOnEpac extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::connection('site_epac')->create('sujets', function (Blueprint $table) {
            $table->id();
            $table->string('titre')->nullable(false);
            $table->longText('contenu')->nullable(false);
            $table->unsignedBigInteger('departement_id')->nullable(false);
           // $table->foreign('departement_id')->references('id')->on('departements')->onDelete('cascade');
            $table->unsignedBigInteger('user_id')->nullable(false);
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });

        Schema::connection('site_epac')->create('commentaires', function (Blueprint $table) {
            $table->id();
            $table->longText('contenu')->nullable(false);
            $table->unsignedBigInteger('sujet_id')->nullable(false);
            $table->foreign('sujet_id')->references('id')->on('sujets')->onDelete('cascade');
            $table->unsignedBigInteger('commentaire_id')->nullable();
            $table->foreign('commentaire_id')->references('id')->on('commentaires')->onDelete('cascade');
            $table->unsignedBigInteger('user_id')->nullable(false);
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });


        Schema::connection('site_epac')->create('debouches', function (Blueprint $table) {

            $table->id();
            $table->unsignedBigInteger('filiere_id')->nullable();
            $table->string('titre');
            $table->longText('description');
            $table->longText('mission');
            $table->unsignedBigInteger('departement_id')->nullable();
           // $table->foreign('departement_id')->references('id')->on('departements')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });

        Schema::connection('site_epac')->create('competences', function (Blueprint $table) {

            $table->id();
            $table->unsignedBigInteger('filiere_id')->nullable();
            $table->longText('texte');
            $table->unsignedBigInteger('departement_id')->nullable();
           // $table->foreign('departement_id')->references('id')->on('departements')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });

        Schema::connection('site_epac')->create('images', function (Blueprint $table) {
            $table->id();
            $table->string('nom')->nullable(false);
            $table->string('url')->nullable(false);
            $table->unsignedBigInteger('section_id')->nullable();
            $table->foreign('section_id')->references('id')->on('sections')->onDelete('cascade');
            $table->unsignedBigInteger('sujet_id')->nullable();
            $table->foreign('sujet_id')->references('id')->on('sujets')->onDelete('cascade');
            $table->unsignedBigInteger('commentaire_id')->nullable();
            $table->foreign('commentaire_id')->references('id')->on('commentaires')->onDelete('cascade');
            $table->unsignedBigInteger('debouche_id')->nullable();
            $table->foreign('debouche_id')->references('id')->on('debouches')->onDelete('cascade');
            $table->enum('statut', ['PUBLISHED', 'PENDING', 'BLOCKED', 'SIGNALED', 'DELETED'])->default('PUBLISHED');
            $table->dateTime('created_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->dateTime('updated_at')->nullable(false)->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::connection('site_epac')->dropIfExists('images');
        Schema::connection('site_epac')->dropIfExists('commentaires');
        Schema::connection('site_epac')->dropIfExists('sujets');
    }
}
