<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('products', function (Blueprint $table) {

            $table->id();

            $table->foreignId('category_id')
                ->constrained()
                ->cascadeOnDelete();

            $table->string('product_name',150);

            $table->string('product_code',50)->unique();

            $table->text('description')->nullable();

            $table->decimal('price',10,2);

            $table->decimal('discount_price',10,2)->nullable();

            $table->string('unit',50)->nullable();

            $table->string('product_image')->nullable();

            $table->integer('display_order')->default(0);

            $table->boolean('status')->default(true);

            $table->timestamps();

            $table->index(['category_id','status']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('products');
    }
};