<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::table('cars', function (Blueprint $table) {
            if (!Schema::hasColumn('cars', 'engine')) {
                $table->string('engine')->nullable()->after('color');
            }
            if (!Schema::hasColumn('cars', 'transmission')) {
                $table->enum('transmission', ['automatic', 'manual'])->default('automatic')->after('engine');
            }
        });
    }

    public function down()
    {
        Schema::table('cars', function (Blueprint $table) {
            if (Schema::hasColumn('cars', 'engine')) {
                $table->dropColumn('engine');
            }
            if (Schema::hasColumn('cars', 'transmission')) {
                $table->dropColumn('transmission');
            }
        });
    }
};
