<?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->increments('product_id'); // int NOT NULL, auto-incrementing primary key
            $table->longText('product_code')->nullable();
            $table->integer('category_id')->unsigned()->nullable();
            $table->integer('brand_id')->unsigned()->nullable();
            $table->integer('style_id')->unsigned()->nullable();
            $table->integer('size_id')->unsigned()->nullable();
            $table->integer('color_id')->unsigned()->nullable();
            $table->integer('threshold')->default(2);
            $table->integer('product_quantity')->default(0);
            $table->integer('product_manual_quantity')->default(0);
            $table->decimal('product_mrp', 10, 2)->default(0.00);
            $table->decimal('product_price', 10, 2)->default(0.00);
            $table->boolean('active_status')->default(0);
            $table->timestamps();
            $table->softDeletes(); // This creates a nullable 'deleted_at' timestamp column

            // Foreign key constraints
            $table->foreign('category_id')->references('category_id')->on('categories')->onDelete('set null');
            $table->foreign('brand_id')->references('brand_id')->on('brands')->onDelete('set null');
            $table->foreign('style_id')->references('style_id')->on('styles')->onDelete('set null');
            $table->foreign('size_id')->references('size_id')->on('sizes')->onDelete('set null');
            $table->foreign('color_id')->references('color_id')->on('colors')->onDelete('set null');
        });
    }

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