<?php

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

class AddMaintenanceFieldsToEquipment extends Migration
{
    public function up()
    {
        Schema::table('equipment', function (Blueprint $table) {
            // First add last_maintenance_date if needed
            if (!Schema::hasColumn('equipment', 'last_maintenance_date')) {
                $table->date('last_maintenance_date')->nullable()->after('status');
            }
            
            // Then add maintenance_status
            if (!Schema::hasColumn('equipment', 'maintenance_status')) {
                $table->string('maintenance_status')
                      ->default('operational')
                      ->after('last_maintenance_date');
            }
        });
    }

    public function down()
    {
        Schema::table('equipment', function (Blueprint $table) {
            $table->dropColumn(['last_maintenance_date', 'maintenance_status']);
        });
    }
}