<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('drivers', function (Blueprint $table) {
            // إضافة الأعمدة المفقودة مع التحقق من وجودها
            if (!Schema::hasColumn('drivers', 'vehicle_type')) {
                $table->string('vehicle_type')->after('license_number')->default('sedan');
            }
            
            if (!Schema::hasColumn('drivers', 'experience_years')) {
                $table->integer('experience_years')->after('vehicle_type')->default(0);
            }
            
            if (!Schema::hasColumn('drivers', 'current_status')) {
                $table->string('current_status')->after('is_available')->nullable();
            }
            
            if (!Schema::hasColumn('drivers', 'last_seen')) {
                $table->timestamp('last_seen')->after('current_status')->nullable();
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('drivers', function (Blueprint $table) {
            if (Schema::hasColumn('drivers', 'last_seen')) {
                $table->dropColumn('last_seen');
            }
            
            if (Schema::hasColumn('drivers', 'current_status')) {
                $table->dropColumn('current_status');
            }
            
            if (Schema::hasColumn('drivers', 'experience_years')) {
                $table->dropColumn('experience_years');
            }
            
            if (Schema::hasColumn('drivers', 'vehicle_type')) {
                $table->dropColumn('vehicle_type');
            }
        });
    }
};
