<?php

use App\Models\ProductManagement\Category;
use App\Models\ProductManagement\Product;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(){
        Schema::create((new Product)->getTable(), function (Blueprint $table) {
            $table->id();
            $table->string('ref')->unique()->nullable()
                ->comment("La référence unique du produit");
            $table->string('name')->index();
            $table->string('slug')->unique();
            $table->text('description');
            $table->longText('details');
            $table->double('price');
//            $table->integer('quantity')->default(0);
            $table->boolean('featured')->default(0);
            $table->boolean('active')->default(false);
            $table->unsignedTinyInteger('review_able')->default(1);

            $table->foreignIdFor(Category::class,'category_id')
                ->constrained((new Category)->getTable(), (new Category)->getKeyName())
                ->cascadeOnUpdate()->cascadeOnDelete()
                ->comment("[FK] La categorie");

            $table->timestamps();
            $table->softDeletes();
        });
    }

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