<?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::table('settings', function (Blueprint $table) {
            $table->string('label', 150)->nullable()->after('type');
            $table->integer('order_index')->default(0)->after('label');

            // Replace unique key constraint to (group, key) combo
            $table->dropUnique(['key']);
            $table->unique(['group', 'key']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('settings', function (Blueprint $table) {
            $table->dropUnique(['group', 'key']);
            $table->unique('key');
            $table->dropColumn(['label', 'order_index']);
        });
    }
};
