<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('website_sections', function (Blueprint $table) {
            $table->id();
            $table->foreignId('academy_id')->constrained('academies');
            $table->string('section_key', 50);
            $table->string('title')->nullable();
            $table->string('title_en')->nullable();
            $table->string('subtitle')->nullable();
            $table->string('subtitle_en')->nullable();
            $table->text('content')->nullable();
            $table->text('content_en')->nullable();
            $table->jsonb('settings')->default('{}');
            $table->unsignedSmallInteger('sort_order')->default(0);
            $table->boolean('is_enabled')->default(true);
            $table->timestamps();

            $table->unique(['academy_id', 'section_key']);
            $table->index(['academy_id', 'sort_order']);
        });

        DB::statement("ALTER TABLE website_sections ADD CONSTRAINT website_sections_section_key_check
            CHECK (section_key IN ('hero', 'about', 'activities', 'programs', 'branches',
            'schedule', 'trainers', 'gallery', 'testimonials', 'pricing', 'partners',
            'contact', 'faq', 'cta', 'stats', 'news'))");
    }

    public function down(): void
    {
        Schema::dropIfExists('website_sections');
    }
};
