<?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('trucks', function (Blueprint $table) {
            // Add 'name' only if it doesn't already exist
            if (!Schema::hasColumn('trucks', 'name')) {
                $table->string('name', 100)->after('number');
            }
            // Drop 'type' only if it exists
            if (Schema::hasColumn('trucks', 'type')) {
                $table->dropColumn('type');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('trucks', function (Blueprint $table) {
            $table->enum('type', ['dry_van', 'reefer', 'flatbed'])->after('number');
            $table->dropColumn('name');
        });
    }
};
