<?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_settings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('academy_id')->unique()->constrained('academies');
            $table->string('template', 30)->default('bold_athletic');

            // Colors
            $table->string('primary_color', 7)->default('#1a1a2e');
            $table->string('secondary_color', 7)->default('#16213e');
            $table->string('accent_color', 7)->default('#e94560');
            $table->string('text_color', 7)->default('#ffffff');

            // Typography
            $table->string('heading_font', 50)->default('Cairo');
            $table->string('body_font', 50)->default('Cairo');

            // Layout
            $table->string('navbar_style', 20)->default('transparent');

            // Content
            $table->string('site_title')->nullable();
            $table->string('site_title_en')->nullable();
            $table->text('site_description')->nullable();
            $table->text('site_description_en')->nullable();
            $table->jsonb('social_links')->default('{}');
            $table->string('whatsapp_number', 20)->nullable();

            // Advanced
            $table->text('custom_css')->nullable();
            $table->string('google_analytics_id', 30)->nullable();
            $table->string('facebook_pixel_id', 30)->nullable();

            // Publish state
            $table->boolean('is_published')->default(false);
            $table->timestamp('published_at')->nullable();

            $table->timestamps();
        });

        DB::statement("ALTER TABLE website_settings ADD CONSTRAINT website_settings_template_check
            CHECK (template IN ('bold_athletic', 'clean_professional', 'vibrant_playful'))");

        DB::statement("ALTER TABLE website_settings ADD CONSTRAINT website_settings_navbar_style_check
            CHECK (navbar_style IN ('solid', 'transparent', 'floating'))");
    }

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