<?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::table('homepage_sections', function (Blueprint $table) {
            $table->string('page_slug')->default('home')->after('id');
            $table->integer('sort_order')->default(0)->after('is_active');
            $table->dropUnique('homepage_sections_section_key_unique');
            // Allow duplicate keys across different pages but unique on one page
            $table->unique(['page_slug', 'section_key']); 
        });
    }

    public function down(): void
    {
        Schema::table('homepage_sections', function (Blueprint $table) {
            $table->dropUnique(['page_slug', 'section_key']);
            $table->unique('section_key');
            $table->dropColumn(['page_slug', 'sort_order']);
        });
    }
};
