<?php

use App\Models\SettingManagement\Status;
use App\Models\SettingManagement\StatusChange;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {

    public function up(){

        Schema::create( (new StatusChange)->getTable() , function (Blueprint $table) {
            $table->id();

            $table->string(StatusChange::MORPH_ID_COLUMN, 60)->nullable()
                  ->comment("[polymorph_id] l'id du model qui est audité  (ex : '1')");
            $table->string(StatusChange::MORPH_TYPE_COLUMN, 100)->nullable()
                  ->comment("[polymorph_type] le type du model audité  nom de cette table utilisé par laravel)
                  pour faire la correspondance de l'enregistrement  (ex : 'user')");

            $table->foreignIdFor(Status::class,'status_code')
                ->constrained((new Status)->getTable(), (new Status)->getKeyName())
                ->cascadeOnUpdate()->cascadeOnDelete()
                ->comment("[FK] le statut associé");

            $table->timestamp("created_at");
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(){
        Schema::dropIfExists((new StatusChange)->getTable());
    }
};
