<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('title');
            $table->string('slug')->unique();
            $table->text('description');
            $table->text('detail');
            $table->text('matetial');
            $table->text('care');
            $table->decimal('price', 10, 2)->unsigned();
            $table->decimal('discount_price', 10, 2)->nullable()->unsigned();
            $table->integer('stock')->default(0);
            $table->string('product_code');
            $table->unsignedBigInteger('category_id'); 
            $table->unsignedBigInteger('subcategory_id')->nullable(); 
            $table->foreign('category_id')->references('id')->on('menus')->onDelete('cascade');
            $table->foreign('subcategory_id')->references('id')->on('menus')->onDelete('cascade');
            $table->string('thumbnail');
            $table->string('brand_name')->nullable();
            $table->string('sku')->nullable();
            $table->string('alt');
            $table->enum('status', ['in-stock', 'out-of-stock'])->comment('in-stock, out-of-stock')->default('in-stock');
            $table->integer('sold_count')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::disableForeignKeyConstraints();
      
        Schema::dropIfExists('products');
        Schema::enableForeignKeyConstraints();
        
    }
};
