<?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('speaker_types', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->string('color')->default('primary');
            $table->text('description')->nullable();
            $table->boolean('is_active')->default(true);
            $table->integer('order')->default(0);
            $table->timestamps();
        });

        // Add foreign key to speakers table
        Schema::table('speakers', function (Blueprint $table) {
            $table->foreignId('speaker_type_id')->nullable()->after('type')->constrained('speaker_types')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('speakers', function (Blueprint $table) {
            $table->dropForeign(['speaker_type_id']);
            $table->dropColumn('speaker_type_id');
        });
        Schema::dropIfExists('speaker_types');
    }
};
