<?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('trip_requests')) {
            return;
        }

        Schema::table('trip_requests', function (Blueprint $table) {
            if (! Schema::hasColumn('trip_requests', 'wheel_milestone_pending')) {
                $table->boolean('wheel_milestone_pending')->default(false);
            }
            if (! Schema::hasColumn('trip_requests', 'wheel_promo_fee_amount')) {
                $table->decimal('wheel_promo_fee_amount', 12, 2)->nullable();
            }
            if (! Schema::hasColumn('trip_requests', 'wheel_result')) {
                $table->unsignedTinyInteger('wheel_result')->nullable();
            }
            if (! Schema::hasColumn('trip_requests', 'wheel_spun_at')) {
                $table->timestamp('wheel_spun_at')->nullable();
            }
        });
    }

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

        Schema::table('trip_requests', function (Blueprint $table) {
            foreach (['wheel_milestone_pending', 'wheel_promo_fee_amount', 'wheel_result', 'wheel_spun_at'] as $col) {
                if (Schema::hasColumn('trip_requests', $col)) {
                    $table->dropColumn($col);
                }
            }
        });
    }
};
