<?php

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

class CreateBibliothequeProjets extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('bibliotheque_projets', function (Blueprint $table) {
            $table->id();
            $table->timestamps();

            $table->integer('structure_id')->unsigned();
            $table->integer('direction_id')->unsigned();
            $table->integer('service_id')->unsigned();
            $table->string('objet');
            $table->text('description')->nullable();
            $table->integer('niveau_mutualisation_id')->unsigned();
            $table->integer('operateur_mutualisation_id')->unsigned();
            $table->enum('budget', ['investissement', 'exploitation'])->nullable(false);
            $table->decimal('impact_budgetaire',5,2)->default('0');
            $table->integer('imputation_budgetaire_id')->unsigned();
            $table->tinyInteger('programmation');
            $table->unsignedTinyInteger('type_calcul_gains');
            $table->tinyInteger('ondam');
            $table->boolean('referentiel')->nullable();
            $table->integer('famille_id')->unsigned()->nullable();
            $table->integer('domaine_id')->unsigned()->nullable();
            $table->integer('categorie_id')->unsigned()->nullable();
            $table->integer('segment_id')->unsigned()->nullable();
            $table->boolean('renouvellement_marche')->nullable(true);
            $table->string('libelle_marche_a_renouveler')->nullable();
            $table->string('numero_marche_a_renouveler')->nullable();
            $table->string('libelle_nouveau_marche')->nullable();
            $table->string('numero_nouveau_marche')->nullable();
            $table->date('date_debut');
            $table->date('date_fin');


            // $table->integer('finess')->nullable();
            // $table->date('date_mise_en_oeuvre')->nullable();
            // $table->string('code_nomenclature',45)->nullable();
            // $table->integer('montant_reference')->nullable();
            // $table->integer('montant_notifie')->nullable();
            // $table->integer('montant_realise')->nullable();
            // $table->tinyInteger('is_achat_complexe');
            // $table->decimal('pourcentage_gains_cible',5,2)->nullable();
            // $table->integer('gains_cible')->nullable();
            // $table->integer('gains_notifie')->nullable();
            // $table->integer('gains_securise')->nullable();
            // $table->integer('duree_mois')->nullable();
            // $table->text('commentaire')->nullable();
            // $table->tinyInteger('programme')->default('0');
            // $table->tinyInteger('soumis')->default('0');
            // $table->date('prochaine_echeance')->nullable();
            // $table->text('prochaine_etape')->nullable();
            // $table->text('etat_avancement')->nullable();
            // $table->tinyInteger('cloture')->default('0');
            // $table->tinyInteger('valide_controleur_gestion')->default('0');
            // $table->enum('risque',['maitrise','retard','retard_important'])->default('maitrise');
            // $table->integer('paat_id')->unsigned();
            // $table->integer('owner_id')->unsigned();

            // $table->foreign('paat_id')->references('id')->on('paats');
            // $table->foreign('owner_id')->references('id')->on('users');
            $table->foreign('structure_id')->references('id')->on('structures');
            $table->foreign('direction_id')->references('id')->on('directions');
            $table->foreign('service_id')->references('id')->on('services');
            $table->foreign('niveau_mutualisation_id')->references('id')->on('niveaux_mutualisations');
            $table->foreign('operateur_mutualisation_id')->references('id')->on('operateurs_mutualisations');
            $table->foreign('imputation_budgetaire_id')->references('id')->on('imputations_budgetaires');
            $table->foreign('famille_id')->references('id')->on('familles');
            $table->foreign('domaine_id')->references('id')->on('domaines');
            $table->foreign('categorie_id')->references('id')->on('categories');
            $table->foreign('segment_id')->references('id')->on('segments');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('bibliotheque_projets');
    }
}
