<?php

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

class CreateCategoriesTable20250428051002 extends Migration
{
    public function up(): void
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('section_id');
            $table->unsignedBigInteger('parent_id')->default(0);
            $table->string('name')->unique();
            $table->decimal('commission_rate', 5, 2);
            $table->text('description')->nullable();
            $table->string('picture')->nullable();
            $table->string('url');
            $table->string('meta_title')->nullable();
            $table->string('meta_description')->nullable();
            $table->string('meta_keywords')->nullable();
            $table->tinyInteger('status')->default(1);
            $table->timestamps();

            $table->foreign('section_id')->references('id')->on('sections')->onDelete('restrict');
            $table->index('name');
            $table->index('section_id');
        });
    }

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