<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * 
     * Creates the discussion_topics table for organizing discussions into topics.
     * Each topic has a unique name and slug for SEO-friendly URLs.
     * 
     * @return void
     */
    public function up(): void
    {
        Schema::create('discussion_topics', function (Blueprint $table) {
            // Primary key
            $table->id();

            // Topic details - 191 char limit for MySQL 5.7 compatibility
            $table->string('name', 191);
            $table->string('slug', 191)->unique();
            $table->text('description')->nullable();

            // Status and ordering
            $table->boolean('is_active')->default(true);
            $table->integer('sort_order')->default(0);

            // SEO metadata
            $table->string('meta_title', 191)->nullable();
            $table->text('meta_description')->nullable();
            $table->string('meta_keywords', 191)->nullable();

            // Icon and color for UI
            $table->string('icon', 50)->default('fa-comments');
            $table->string('color', 20)->default('green');

            // Timestamps
            $table->timestamps();
            $table->softDeletes();

            // Indexes for performance
            $table->index('is_active');
            $table->index('sort_order');
            $table->index('created_at');
        });
    }

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