<?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('vehicles', function (Blueprint $table) {
            if (!Schema::hasColumn('vehicles', 'image')) {
                $table->string('image')->nullable()->after('vehicle_type');
            }
            if (!Schema::hasColumn('vehicles', 'has_ac')) {
                $table->boolean('has_ac')->default(true)->after('image');
            }
            if (!Schema::hasColumn('vehicles', 'passenger_count')) {
                $table->unsignedTinyInteger('passenger_count')->default(4)->after('has_ac');
            }
            if (!Schema::hasColumn('vehicles', 'is_4wd')) {
                $table->boolean('is_4wd')->default(false)->after('passenger_count');
            }
            if (!Schema::hasColumn('vehicles', 'service_type')) {
                $table->string('service_type')->default('taxi')->after('is_4wd'); // taxi, private, saloon
            }
        });
    }

    public function down(): void
    {
        Schema::table('vehicles', function (Blueprint $table) {
            $columns = ['image', 'has_ac', 'passenger_count', 'is_4wd', 'service_type'];
            foreach ($columns as $col) {
                if (Schema::hasColumn('vehicles', $col)) {
                    $table->dropColumn($col);
                }
            }
        });
    }
};
