<?php

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

/**
 * Presentation settings the navbar and footer had no way to express.
 *
 * - `navbar_secondary_logo_path`: a second lock-up beside the academy logo, for
 *   organisations that co-brand (a parent company, a sponsor lock-up).
 * - `navbar_show_language`: whether the public navbar offers a language switch.
 *   Defaults to false so no existing site grows a control it never had.
 * - `footer_powered_by`: an optional accent bar under the footer — a label and
 *   a list of logos. Null means no bar, which is what every current site shows.
 *
 * All three are additive and nullable; a site that never sets them renders
 * exactly as it does today.
 */
return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('website_settings')) {
            return;
        }

        Schema::table('website_settings', function (Blueprint $table) {
            if (! Schema::hasColumn('website_settings', 'navbar_secondary_logo_path')) {
                $table->string('navbar_secondary_logo_path')->nullable()->after('navbar_logo_position');
            }
            if (! Schema::hasColumn('website_settings', 'navbar_show_language')) {
                $table->boolean('navbar_show_language')->default(false)->after('navbar_secondary_logo_path');
            }
            if (! Schema::hasColumn('website_settings', 'footer_powered_by')) {
                $table->jsonb('footer_powered_by')->nullable()->after('footer_bottom_text');
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('website_settings')) {
            return;
        }

        Schema::table('website_settings', function (Blueprint $table) {
            foreach (['footer_powered_by', 'navbar_show_language', 'navbar_secondary_logo_path'] as $column) {
                if (Schema::hasColumn('website_settings', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};
