<?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('sliders', function (Blueprint $table) {
            if (!Schema::hasColumn('sliders', 'title')) {
                $table->string('title')->nullable()->after('image');
            }

            if (!Schema::hasColumn('sliders', 'description')) {
                $table->text('description')->nullable()->after('title');
            }

            if (!Schema::hasColumn('sliders', 'youtube_url')) {
                $table->text('youtube_url')->nullable()->after('description');
            }
        });

        Schema::table('sliders', function (Blueprint $table) {
            $table->string('image')->nullable()->change();
        });
    }

    public function down(): void
    {
        Schema::table('sliders', function (Blueprint $table) {
            if (Schema::hasColumn('sliders', 'youtube_url')) {
                $table->dropColumn('youtube_url');
            }

            if (Schema::hasColumn('sliders', 'description')) {
                $table->dropColumn('description');
            }

            if (Schema::hasColumn('sliders', 'title')) {
                $table->dropColumn('title');
            }
        });
    }
};
