<?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
    {
        if (! Schema::hasTable('dealers')) {
            return;
        }

        Schema::table('dealers', function (Blueprint $table): void {
            if (! Schema::hasColumn('dealers', 'login_background_path')) {
                $table->string('login_background_path', 255)->nullable()->after('favicon_path');
            }
            if (! Schema::hasColumn('dealers', 'login_logo_path')) {
                $table->string('login_logo_path', 255)->nullable()->after('login_background_path');
            }
            if (! Schema::hasColumn('dealers', 'login_accent_color')) {
                $table->string('login_accent_color', 32)->nullable()->after('login_logo_path');
            }
        });
    }

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

        Schema::table('dealers', function (Blueprint $table): void {
            foreach (['login_background_path', 'login_logo_path', 'login_accent_color'] as $column) {
                if (Schema::hasColumn('dealers', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};

