<?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
    {
        // Primero eliminar la columna antigua (si existe) y crear la nueva
        Schema::table('inspections', function (Blueprint $table) {
            // Si ya existe como string, la eliminamos
            if (Schema::hasColumn('inspections', 'feature_id')) {
                $table->dropColumn('feature_id');
            }
            $table->foreignId('feature_id')->constrained('features')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('inspections', function (Blueprint $table) {
            $table->dropForeign(['feature_id']);
            $table->dropColumn('feature_id');
            $table->string('feature_id')->nullable(); // rollback opcional
        });
    }
};
