<?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->foreignId('parent_id')->nullable()->constrained('products')->cascadeOnDelete();
            $table->foreignId('brand_id')->nullable()->constrained('brands')->cascadeOnDelete();

            $table->string('name')->index();
            $table->string('slug')->unique();
            $table->text('description')->nullable();

            $table->string('sku')->index()->nullable(); // "Unique" ???
            $table->string('barcode')->index()->nullable(); // "Unique" ???
            $table->integer('stock')->nullable()->default(0);
            $table->integer('security_stock')->nullable()->default(0);

            $table->decimal('old_price_amount', 15, 2)->nullable();
            $table->decimal('price_amount', 15, 2)->nullable();
            $table->decimal('cost_amount', 15, 2)->nullable();

            $table->string('seo_title')->nullable();
            $table->string('seo_description')->nullable();

            $table->jsonb('options')->nullable();

            $table->boolean('is_visible')->default(true);
            $table->timestamps();
        });
    }

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