<?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('feature_types', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('description')->nullable();
            $table->string('color', 7)->default('#6b7280');
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::table('features', function (Blueprint $table) {
            $table->foreignId('feature_type_id')->nullable()->after('template_id')
                ->constrained('feature_types')->nullOnDelete();
            $table->boolean('is_active')->default(true)->after('status');
        });
    }

    public function down(): void
    {
        Schema::table('features', function (Blueprint $table) {
            $table->dropConstrainedForeignId('feature_type_id');
            $table->dropColumn('is_active');
        });

        Schema::dropIfExists('feature_types');
    }
};
